Java 4 line


  • 0
    A
    public void moveZeroes(int[] nums) {
        int left = 0;
        for(int i=0; i<nums.length; i++) if(nums[i]==0) {left = i; break;}
        for(int i=left; i<nums.length; i++) if(nums[i]!=0) nums[left++] = nums[i];
        while(left<nums.length) nums[left++] = 0;
    }

Log in to reply
 

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