程式語言 - LeetCode - C - Two Pointers



參考資訊:
https://www.cnblogs.com/grandyang/p/4822732.html

題目:


解答:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void moveZeroes(int* nums, int numsSize)
{
    int cc = 0;
    int idx = 0;
 
    for (cc = 0; cc < numsSize; cc++) {
        if (nums[cc]) {
            nums[idx] = nums[cc];
 
            if (cc != idx) {
                nums[cc] = 0;
            }
            idx += 1;
        }
    }   
}