My C solution,Runtime: 6 ms


  • 0
    A
    void moveZeroes(int* nums, int numsSize) {
        /*two pointers*/
        int i = 0, j = 1;
        while (j < numsSize) {
            if (!(nums[i] | nums[j])) {
                i--;
            } else if (nums[i] == 0) {
                nums[i] = nums[j];
                nums[j] = 0;
            }
            i++; j++;
        }
    
        return;
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.