217. Contains Duplicate
2016-02-25 10:00
531 查看
解法一:
解法二:
public class Solution { public boolean containsDuplicate(int[] nums) { HashSet<Integer> hasSet = new HashSet<>(); for (int i = 0; i < nums.length; i++) { if (hasSet.contains(nums[i])) return true; else hasSet.add(nums[i]); } return false; } }
解法二:
Arrays.sort(nums); for (int i = 0; i < nums.length-1; i++) { if (nums[i]==nums[i+1]) { return true; } } return false;
相关文章推荐
- AIX ERRPT日志查询
- RAID5磁盘阵列配置
- Could not obtain transaction-synchronized Session for current thread 异常处理方式
- User Agent String explained
- 报错:Conversion to Dalvik format failed: Unable to execute dex:
- 217. Contains Duplicate
- Does Daemon Thread Exit with Main Thread?
- Exchange2010使用 Export-Mailbox cmdlet 将邮箱的内容移动到指定的邮箱文件夹
- HDU 3264 Open-air shopping malls(计算几何 && 二分优化)
- hdu2467 String painter(区间dp)
- UVA253 Cube painting
- Zookeeper异常:FAILED TO WRITE PID与Permission denied
- Container With Most Water
- AIDL随写
- 高僧斗法--Staircase Nim
- poj 1363 Rails(栈)
- 【bzoj2434】[Noi2011]阿狸的打字机 AC自动机+fail树+dfs序+树状数组
- 欢迎使用CSDN-markdown编辑器
- How Does Caching Work in AFNetworking? : AFImageCache & NSUrlCache Explained
- 【bzoj3172】[Tjoi2013]单词 AC自动机+fail树