(easy)LeetCode 217.Contains Duplicate
2015-07-31 20:14
639 查看
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.
代码如下:
运行结果:
代码如下:
public class Solution { public boolean containsDuplicate(int[] nums) { Set<Integer> set=new HashSet<Integer>(); int len=nums.length; for(int i=0;i<len;i++){ set.add(nums[i]); } if(len>set.size()) return true; else return false; } }
运行结果:
相关文章推荐
- HUAS Summer Trainning #3~C
- HDU 5328 Problem Killer (2015 Multi-University Training Contest 4 2015多校联合)
- Doing Homework again
- HDU 5327 Olympiad (2015 Multi-University Training Contest 4 2015多校联合)
- hdu 1789 Doing Homework again
- waiting for xdebug session
- HUAS Summer Trainning #3~K
- Hdu 5309 JRY is Fighting 2015 Multi-University Training Contest 2
- 2015 Multi-University Training Contest 1(HDOJ5288、5289)
- sleep和wait有什么区别
- hdoj 1789 Doing Homework again
- HDU1789:Doing Homework again 【贪心】
- LeetCode219——Contains Duplicate II
- hdu杭电1789 Doing Homework again【优先队列+贪心】
- HDOJ 1789 Doing Homework again(贪心,好题)
- PicklingError: Can't pickle <type 'thread.lock'>: attribute lookup thread.lock failed
- 阿里云SSH "Write failed: Broken pipe"的问题解决方法
- Doing Homework again
- HDOJ Doing Homework again (贪心+优先队列)
- 2015 Multi-University Training Contest 4--多校赛第四场--做完了再添加上来