Succinct Java Solution


  • -1
    O

    Move through the array and swap non-zeros to the front.

    public void moveZeroes(int[] nums) {
      for (int a = 0, b = 0; a < nums.length; a++) if (nums[a] != 0) swap(nums, a, b++);
    }

Log in to reply
 

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