Contains Duplicate
2015-07-08 10:50
204 查看
查找是否存在重复的数,直接定义map进行记录。或者用哈希也可以。
class Solution { public: bool containsDuplicate(vector<int>& nums) { map<int,int> mymap; int size=nums.size(); for(int i=0;i<size;i++) { if(mymap.find(nums[i])==mymap.end()) { mymap.insert(pair<int,int>(nums[i],1)); } else { return true; } } return false; } };
相关文章推荐
- Contains Duplicate II
- Loadrunner:POP3协议录制收信,使用foxmail录制到的脚本为空
- Failed to fetch URL https://dl-ssl.google.com/android/repository/addons_list-2.xml, reason:
- WebLogic11g-创建域(Domain)
- HDU 5052 Yaoge’s maximum profit 光秃秃的树链拆分 2014 ACM/ICPC Asia Regional Shanghai Online
- HDU 5228 ZCC loves straight flush( BestCoder Round #41)
- loadrunner场景中Erro.. Failed to connect to load generator.Check the output windows for more details
- RAINLOOP WEBMAIL INSTALLATION
- retain的循环引用注意以及@class的使用
- Number of Containers(数学)
- DELL R430安装WINDOWS 2008 R2 RAID卡无驱动
- glib g_main_loop理解
- cache_peer和cache_peer_domain详解
- 关于main函数中argc和argv的简单介绍
- [Leetcode]-Contains Duplicate HashTbale重解
- Available Bandwidth paper(3)
- Contains Duplicate II
- 【LeetCode】219. Contains Duplicate II
- Contains Duplicate II
- 实战weblogic集群之创建domain,AdminServer