AC solution with avoid swap (0,0)


  • 0
    C
    void moveZeroes(int* nums, int numsSize) {
        int i = 0, j = 0;
    
        while (nums[i] && i < numsSize){ i++, j++; }
        for (; j < numsSize;j++){
            if (nums[j]){
                nums[i++] = nums[j];
                nums[j] = 0;
            }
        }
    
        return;
    }

Log in to reply
 

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