Java very simple solution with complexity 0(2n), Runtime: 0 ms,beats 64.59% submissions


  • 0
    V
    	public void moveZeroes(final int[] nums) {
    			int zeroCounter = 0;
    			for (int i = 0; i < nums.length; i++)
    			{
    				final int num = nums[i];
    				if(num == 0){
    					zeroCounter++;
    				}else if (zeroCounter!=0){
    					nums[i-zeroCounter] = num;
    					nums[i] = 0;
    				}
    			}
    		}
    

Log in to reply
 

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