leetcode Contains Duplicate
2015-11-13 13:13
507 查看
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.
Subscribe to see which companies asked this question
用map做的很简单,不赘述
Subscribe to see which companies asked this question
用map做的很简单,不赘述
class Solution { public: bool containsDuplicate(vector<int>& nums) { map<int,int> M1; int temp; if (nums.empty()) return false; for(auto i=nums.begin();i!=nums.end();i++){ temp=(*i); ++M1[temp]; } for(auto j=M1.begin();j!=M1.end();j++){ if((*j).second>1) return true; } return false; } };
相关文章推荐
- 移动止损(Trailing Stop)
- retain
- POSIX的pthread_join http://blog.csdn.net/ba_jie/article/details/6783205
- FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.tez.TezTask
- Rails接口(interface)入门
- 【Codeforces Round 323 (Div 2)D】【暴力 脑洞 插入贡献思想】Once Again... 循环节重复T次后的LIS
- Vehicle Logo Recognition System Based on Convolutional Neural Networks With a Pretraining Strategy
- There is only one kind of failure,that is to give up halfway.
- void pthread_exit(void *retval) http://blog.csdn.net/youbang321/article/details/7816016
- pthread_t http://baike.baidu.com/link?url=RqlQDsuzwglrupfhdmk8nqPkvLSsdSPArFVn9k2nZitvJroW313ALYlsM
- 关于retain以及copy特质的理解
- jetbrains IDEs激活码
- 画刷(QBrush)和画笔(QPen) 都是用来定义QPainter
- LeetCode(219) Contains Duplicate II
- C语言中restrict关键字学习 http://blog.csdn.net/llf021421/article/details/8092602
- 发现大量的TIME_WAIT解决办法
- pthread_create线程创建的过程剖析 http://blog.csdn.net/yetyongjin/article/details/7673837
- pthread_create用法 http://blog.csdn.net/tommy_wxie/article/details/8545253
- AIR ANE应用添加KeyMob广告管理库详细教程
- IBM X335 RAID1 制作