C solution 8ms, easy understand


  • 0
    void moveZeroes(int* nums, int numsSize) {
        int zeroCount = 0;
        for(int i=0; i<numsSize; i++){
            nums[i-zeroCount] = nums[i];
            if(nums[i]==0) zeroCount++;
        }
        for(int i=0; i<zeroCount; i++) nums[numsSize-i-1] = 0;
    }
    

Log in to reply
 

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