simple O(n) C solution


  • 0
    void moveZeroes(int* nums, int numsSize) {
        int cnt = 0;
        int i;
    
        for(i = 0; i < numsSize ;i++){
            if(nums[i] == 0) 
                continue;
            else if(i == cnt){ 
                cnt++;
                continue;
            }
            else{
                nums[cnt] = nums[i];
                nums[i] = 0;
                cnt++;
            }
        }
    }

Log in to reply
 

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