Java 8 - Using streams (improved)


  • 0
    W
     public void moveZeroes(int[] nums) {
            
            ArrayList<Integer> zeros = (ArrayList<Integer>) IntStream.of(nums).boxed().filter(u -> u == 0 ).collect(Collectors.toList());
    		ArrayList<Integer> nozeros = (ArrayList<Integer>) IntStream.of(nums).boxed().filter(u -> u != 0 ).collect(Collectors.toList());
    		nozeros.addAll(zeros);
    		nums = nozeros.stream().mapToInt(u -> u ).toArray();
        }

Log in to reply
 

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