Leetcode: Contains Duplicate
2015-12-17 07:01
519 查看
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
Use HashSet:
public class Solution { public boolean containsDuplicate(int[] nums) { if (nums==null || nums.length==0) return false; HashSet<Integer> set = new HashSet<Integer>(); for (int elem : nums) { if (set.contains(elem)) return true; else { set.add(elem); } } return false; } }
相关文章推荐
- http://blog.csdn.net/linjingj/article/details/18881755
- 将PPT文件内容转换为图片放在Email邮件正文中发送
- LeetCode 172:Factorial Trailing Zeroes
- main函数的三个入参
- Daily Scrum NO.6
- printf的重入问题及解决方法 http://blog.csdn.net/iefswang/article/details/7523458
- Daily Scrumming* 2015.12.16(Day 8)
- Hotspot & Airplane mode
- <LeetCode OJ> 70. Climbing Stairs
- TypeError: 'module' object is not callable cp fromhttp://blog.csdn.net/huang9012/article/details/17417133
- 删除本地过期图pain
- hdu 3980 Paint Chain sg函数
- iTunes store operation failed: You are not authoried to use this service
- explain extend
- 偶尔发生File has been moved - cannot be read again
- 使用lingpipe自然语言处理包进行文本分类/** * 使用 lingpipe的tf/idf分类器训练语料 * * @author laigood */ public class trai
- Unix域套接字(Unix Domain Socket)介绍
- v$session_wait中参数
- [转载]offsetof与container_of宏
- CClientDC CDC CPaintDC CWindowDC 的区别