217. Contains Duplicate
2016-03-18 20:53
337 查看
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.
twice in the array, and it should return false if every element is distinct.
public class Solution { public boolean containsDuplicate(int[] nums) { HashSet<Integer> set = new HashSet<>(nums.length); for(int i = 0;i<nums.length;i++){ if(set.contains(nums[i]))return true; set.add(nums[i]); } return false; } }
相关文章推荐
- 知乎日报(Know almost daily chrome version)
- 知乎日报(Know almost daily chrome version)
- 删除 除了main.mp4以外的全部文件的脚本
- HibernateException: Could not obtain transaction-synchronized Session for current thread 的解决方法。
- 插入排序—直接插入排序(Straight Insertion Sort)
- aidl ( 六) 加入序列化对象传输
- virt-manager启动本地连接报错:internal error: could not get interface XML description: File operation failed
- 测试用例设计之三——OATS PK Pairwise
- 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATIBLE解决办法
- 出现( linker command failed with exit code 1)错误总结
- 已存在的Rails项目部署到heroku
- 解决从jenkins打开robot framework报告会提示‘Opening Robot Framework log failed ’的问题
- 【论文笔记】residual neural network-kaiming he
- Apche Kafka 的生与死 – failover 机制详解
- 十四、职责链(Chain of Responsibility)模式--行为型模式(Behavioral Pattern)
- OC内存分析之retain与copy的简单测试示例
- Precompiling assets failed.remote
- Gradle sync failed: Unable to start the daemon process
- (算法-training)前缀表达式
- (算法-training)Anagrams问题