《leetCode》:Contains Duplicate
2016-03-20 20:38
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.
题目大意:如果数组中有重复的数字,则返回true,否则返回false;
思路
借用一个Set容器即可完成。public boolean containsDuplicate(int[] nums) { if(nums==null){ return false; } Set<Integer> set=new HashSet<Integer>(); for(int i=0;i<nums.length;i++){ if(set.add(nums[i])==false){ return true; } } return false; }
相关文章推荐
- RAID各级别的特性
- RAID各级别的特性
- LeetCode 219. Contains Duplicate II
- 《leetCode》:Contains Duplicate II
- 1014. Waiting in Line (30)
- CodeForces 272C-Dima and Staircase-线段树区间更新-RMQ
- RAID技术介绍和总结
- CodeForces 209C Trails and Glades(欧拉回路判断+并查集计算联通分量)
- alter table *** add constraint *** 用法
- leetcod--Climbing Stairs
- LeetCode 217. Contains Duplicate
- [人工智能] 停机问题、罗素悖论和三值逻辑
- Codility K complementary pairs
- 常用RAID简介
- wait如何处理多进程(多个子进程)
- Factorial Trailing Zeroes
- 深入理解Hadoop YARN中的Container概念
- RAID 图解
- 人工智能有简单的算法吗?Appendix: Is there a simple algorithm for intelligence?
- http://www.nowamagic.net/librarys/veda/detail/1606