JAVA 1ms solution


  • 0
    L

    public class Solution{

    public void moveZeroes(int[] nums) {
    	int z=0;   
    	for(int i=0; i<nums.length; i++){  
    		if(nums[i] == 0){
    			z = i;
    			break;
    		}
    	}
    	if(z!=0 || (z==0 && nums[0]==0)){ 
    		for(int i=z; i<nums.length; i++){ 
    			if(nums[i] !=0 && i>z){
    				nums[z] = nums[i];
    				nums[i] = 0;
    				z++;
    			}
    		}
    	}
    }
    

    }


Log in to reply
 

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