Simple in-place Java.


  • 3
    J
    public void moveZeroes(int[] nums) {
        int i = 0;
        for (int n : nums) {
            if (n != 0)
                nums[i++] = n;
        }
        while (i < nums.length) nums[i++] = 0;
    }

Log in to reply
 

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