C O(n) 6ms real easy


  • 0
    V
    void moveZeroes(int * nums, int numsSize) 
    {
    	int i, j, tmp;
    	
    	for (i = j = 0; i < numsSize; ++i)
    	{
    		if (nums[i])
    		{
    			tmp = nums[i];
    			nums[i] = 0;
    			nums[j++] = tmp;
    		}
    	}
    }
    

Log in to reply
 

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