diff --git a/problems/0283.移动零.md b/problems/0283.移动零.md index 42232cc0..fc708844 100644 --- a/problems/0283.移动零.md +++ b/problems/0283.移动零.md @@ -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; + } +} +``` +