mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
添加0283.激动零 C语言解法
This commit is contained in:
@ -151,6 +151,24 @@ function moveZeroes(nums: number[]): void {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### C
|
||||||
|
|
||||||
|
```c
|
||||||
|
void moveZeroes(int* nums, int numsSize){
|
||||||
|
int fastIndex = 0, slowIndex = 0;
|
||||||
|
for (; fastIndex < numsSize; fastIndex++) {
|
||||||
|
if (nums[fastIndex] != 0) {
|
||||||
|
nums[slowIndex++] = nums[fastIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将slowIndex之后的元素变为0
|
||||||
|
for (; slowIndex < numsSize; slowIndex++) {
|
||||||
|
nums[slowIndex] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user