Contains Duplicate
2015-06-27 23:09
423 查看
Description:
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.
Code:
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.
Code:
bool containsDuplicate(vector<int>& nums) { unordered_map<int,int>m; for (int i = 0; i < nums.size(); ++i) { if (!m.count(nums[i])) m[nums[i]]=i; else return true; } return false; }
相关文章推荐
- Contains Duplicate II
- 线程之sleep(),wait(),yield(),join()等等的方法的区别
- ARM Cortex M0权威指南_PDF电子书下载 带书签目录 高清完整版 http://pan.baidu.com/s/1jGKQSwY MariaDB入门很简单_PDF电子书下载 带
- 【翻译自mos文章】11.2 RAC: In "crsctl stat res -t" State Details May Be Missing or Incorrect
- vs2008 error C2440: “static_cast”: 无法从“void (__thiscall CMainFrame::* )(void)”转换为“LRESULT (__thiscal
- poj 1218 THE DRUNK JAILER
- windows下mysql主从出现Failed to open the relay log(relay_log_pos 248)解决办法
- Naive Bayes 笔记
- HDOJ 5029 Relief grain
- ##MainScene
- 11. Container With Most Water
- 设计模式之二十:责任链模式(Chain of Responsibility)
- WebSocket服务器 CshBBrain
- WebSocket服务器 CshBBrain
- 配置 sendmail 服务器
- head&&tail
- Material Design系列第七篇——Maintaining Compatibility
- Material Design系列第七篇——Maintaining Compatibility
- Dynamics AX 2012 R2 在AIF服务契约中使用DateTime
- 【Hibernate】Hibernate3.x独立运行时的Failed to load class "org.slf4j.impl.StaticLoggerBinder"错误