@Test public void moveZeroesShift() { int[] nums = {0, 5, 66, 0, 12}; int[] result = {5, 66, 12, 0, 0}; MoveZeroesSolution.moveZeroesShiftNonZero(nums); for (int i = 0; i < nums.length; i++) { assertEquals(nums[i], result[i]); } }
static void moveZeroesShiftNonZero(int[] nums) { int len; if (nums == null || (len = nums.length) <= 1) return; int insertPos = 0; for (int num : nums) { if (num != 0) nums[insertPos++] = num; } while (insertPos < len) { nums[insertPos++] = 0; } }
MoveZeroesSolution { static void moveZeroesShiftNonZero(int[] nums) { int len; if (nums == null || (len = nums.length) <= 1) return; int insertPos = 0; for (int num : nums) { if (num != 0) nums[insertPos++] = num; } while (insertPos < len) { nums[insertPos++] = 0; } } }
MoveZeroesSolution { static void moveZeroesShiftNonZero(int[] nums) { int len; if (nums == null || (len = nums.length) <= 1) return; int insertPos = 0; for (int num : nums) { if (num != 0) nums[insertPos++] = num; } while (insertPos < len) { nums[insertPos++] = 0; } }  }
MoveZeroesSolution { static void moveZeroesShiftNonZero(int[] nums) { int len; if (nums == null || (len = nums.length) <= 1) return; int insertPos = 0; for (int num : nums) { if (num != 0) nums[insertPos++] = num; } while (insertPos < len) { nums[insertPos++] = 0; } }   }
MoveZeroesSolution { static void moveZeroesShiftNonZero(int[] nums) { int len; if (nums == null || (len = nums.length) <= 1) return; int insertPos = 0; for (int num : nums) { if (num != 0) nums[insertPos++] = num; } while (insertPos < len) { nums[insertPos++] = 0; } }    }