leetcode 217: Contains Duplicate
2015-06-05 08:27
357 查看
Contains Duplicate
Total Accepted: 8348Total Submissions: 23068
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.
[思路]
Do u really want me to write this?
[CODE]
public class Solution { public boolean containsDuplicate(int[] nums) { Set<Integer> unique = new HashSet<Integer>(); for(int x : nums) { if(unique.contains(x) ) return true; else unique.add(x); } return false; } }
相关文章推荐
- 正确使用Block避免Cycle Retain和Crash
- LeetCode "Contains Duplicate III"
- sgu252:Railway Communication(费用流)
- Climbing Stairs
- 从main函数中argc和argv开始学习
- [LOJ 1038] Race to 1 Again
- How did your survive waiting
- TurboMail智能防御企业邮箱盗号和退信攻击
- tools:context=".MainActivity的作用
- 用libaio读写文件时遇到的问题
- UVA514 Rails
- UVA442 Matrix Chain Multiplication
- light oj 1038 - Race to 1 Again(概率dp求期望 记忆化搜索)
- rails4.2~devise邮箱测试
- hdu 5009 Paint Pearls
- HDU 2476 - String painter(区间DP)
- 【leetcode】Contains Duplicate II
- suspend() 和 resume() 方法,notify()和wait()方法区别
- Splay树(区间添加删除 | 区间翻转)——HDU 3487 Play with Chain
- sizeWithFont:constrainedToSize:转boundingRectWithSize:options: