添加0283.激动零 C语言解法

This commit is contained in:
KingArthur0205
2023-08-23 12:19:29 +08:00
parent 88ca946a7d
commit b985828838

View File

@ -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;
}
}
```