
Find All Duplicates in an Array
Problem
找出数组中所有的重复的数
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
public class { public List<Integer> findDuplicates(int[] nums) { List<Integer> list = new ArrayList<>(); int[] hash = new int[nums.length+1]; for(int i : nums) { if( hash[i]++ == 1) { list.add(i); } } return list; } }
|
近期评论