Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b985828

Browse files
添加0283.激动零 C语言解法
1 parent 88ca946 commit b985828

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

‎problems/0283.移动零.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ function moveZeroes(nums: number[]): void {
151151
};
152152
```
153153

154+
### C
155+
156+
```c
157+
void moveZeroes(int* nums, int numsSize){
158+
int fastIndex = 0, slowIndex = 0;
159+
for (; fastIndex < numsSize; fastIndex++) {
160+
if (nums[fastIndex] != 0) {
161+
nums[slowIndex++] = nums[fastIndex];
162+
}
163+
}
164+
165+
// 将slowIndex之后的元素变为0
166+
for (; slowIndex < numsSize; slowIndex++) {
167+
nums[slowIndex] = 0;
168+
}
169+
}
170+
```
171+
154172
155173
156174

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /