java 1ms clean code!


  • 0
    public void moveZeroes(int[] nums) {
            
            int i = 0;
            for(int j  = 0; j < nums.length; j++) {
                if(nums[j] != 0) {
                    nums[i] = nums[j];
                    if(j > i) nums[j] = 0;
                    i++;
                } 
            }
            
     }
    

Log in to reply
 

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