C solution,O(N)


  • 0
    W
    void moveZeroes(int* nums, int numsSize) {
        int i=0,count=0;
        for(i=0;i<numsSize;i++){
        	if(nums[i]!=0){
        		nums[count]=nums[i];
        		count++;
        	}
        }
        for(i=count;i<numsSize;i++){
        	nums[i]=0;
        }
    }
    

Log in to reply
 

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