4 lines one pass java


  • 0
    T
        public void moveZeroes(int[] nums) {
            int loc = 0;
            while (loc < nums.length && nums[loc] != 0) loc++;
            for (int i = loc + 1; i < nums.length; i++) if (nums[i] != 0) nums[loc++] = nums[i];
            Arrays.fill(nums, loc, nums.length, 0);
        }
    

Log in to reply
 

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