码迷,mamicode.com
首页 > 其他好文 > 详细

217. Contains Duplicate

时间:2016-07-24 08:15:57      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

水一题,一个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     }

 

217. Contains Duplicate

标签:

原文地址:http://www.cnblogs.com/warmland/p/5700034.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!