@Test public void exampleInput() throws Exception { Solution solution = new Solution(); int[] nums = {0, 1, 0, 3, 12}; solution.moveZeroes(nums); assertThat(Arrays.stream(nums).boxed() .collect(Collectors.toList()), hasItems(1, 3, 12, 0, 0)); }
public void moveZeroes(int[] nums) { Map<Boolean, List<Integer>> zeroNoneZeroGroups = IntStream.of(nums).boxed() .collect(Collectors.groupingBy(n -> n == 0)); List<Integer> zeros = zeroNoneZeroGroups.get(true); List<Integer> noneZeros = zeroNoneZeroGroups.get(false); int index = 0; if (noneZeros != null) { for (Integer n : noneZeros) { nums[index] = n; index++; } } if (zeros != null) { for (Integer n : zeros) { nums[index] = n; index++; } } }
Solution { public void moveZeroes(int[] nums) { Map<Boolean, List<Integer>> zeroNoneZeroGroups = IntStream.of(nums).boxed() .collect(Collectors.groupingBy(n -> n == 0)); List<Integer> zeros = zeroNoneZeroGroups.get(true); List<Integer> noneZeros = zeroNoneZeroGroups.get(false); int index = 0; if (noneZeros != null) { for (Integer n : noneZeros) { nums[index] = n; index++; } } if (zeros != null) { for (Integer n : zeros) { nums[index] = n; index++; } } } }
Solution { public void moveZeroes(int[] nums) { Map<Boolean, List<Integer>> zeroNoneZeroGroups = IntStream.of(nums).boxed() .collect(Collectors.groupingBy(n -> n == 0)); List<Integer> zeros = zeroNoneZeroGroups.get(true); List<Integer> noneZeros = zeroNoneZeroGroups.get(false); int index = 0; if (noneZeros != null) { for (Integer n : noneZeros) { nums[index] = n; index++; } } if (zeros != null) { for (Integer n : zeros) { nums[index] = n; index++; } } }  }
Solution { public void moveZeroes(int[] nums) { Map<Boolean, List<Integer>> zeroNoneZeroGroups = IntStream.of(nums).boxed() .collect(Collectors.groupingBy(n -> n == 0)); List<Integer> zeros = zeroNoneZeroGroups.get(true); List<Integer> noneZeros = zeroNoneZeroGroups.get(false); int index = 0; if (noneZeros != null) { for (Integer n : noneZeros) { nums[index] = n; index++; } } if (zeros != null) { for (Integer n : zeros) { nums[index] = n; index++; } } }  void moveZeroes(int[] nums); }
Solution { public void moveZeroes(int[] nums) { Map<Boolean, List<Integer>> zeroNoneZeroGroups = IntStream.of(nums).boxed() .collect(Collectors.groupingBy(n -> n == 0)); List<Integer> zeros = zeroNoneZeroGroups.get(true); List<Integer> noneZeros = zeroNoneZeroGroups.get(false); int index = 0; if (noneZeros != null) { for (Integer n : noneZeros) { nums[index] = n; index++; } } if (zeros != null) { for (Integer n : zeros) { nums[index] = n; index++; } } }  void moveZeroes(int[] nums);  }