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     }

 

posted @ 2016-07-24 07:02  warmland  阅读(99)  评论(0编辑  收藏  举报