217. Contains Duplicate
水一题,一个hashSet记录看到过的
1 public boolean containsDuplicate(int[] nums) { 2 Set<Integer> seen = new HashSet<Integer>(); 3 for(int i = 0; i < nums.length; i++) { 4 if(!seen.contains(nums[i])) { 5 seen.add(nums[i]); 6 } else { 7 return true; 8 } 9 } 10 return false; 11 }