【leetcode】Contains Duplicate
2015-11-19 21:39
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.
Personal Note:
就当复习下map了……
twice in the array, and it should return false if every element is distinct.
class Solution { public: bool containsDuplicate(vector<int>& nums) { map<int, int> tmp; for (int i = 0; i != nums.size(); ++i) { if (!((tmp.insert(pair<int, int>(nums[i], i))).second)) return true; } return false; } };
Personal Note:
就当复习下map了……
相关文章推荐
- PAT-PAT (Advanced Level) Practise Highest Price in Supply Chain(25) 【三星级】
- 【Linux学习笔记】栈与函数调用惯例 http://blog.csdn.net/xiaogugood/article/details/38490663
- Linux内核地址映射模型 http://blog.csdn.net/f22jay/article/details/7925531
- 编译遇到“__stack_chk_fail_local”错误
- [__NSCFString containsString:]: unrecognized selector sent to instance 的解决方案
- 人工智能中的具体搜索方法
- HOJ Train Problem II
- 栈区,堆区,全局区:内存结构图 http://blog.csdn.net/xlf13872135090/article/details/8828704
- 多线程 - 你知道线程栈吗 http://blog.csdn.net/gykimo/article/details/9132157
- 进程线程及堆栈关系的总结 http://blog.csdn.net/echoisland/article/details/6403763
- Daily Scrum - 11/19
- lightoj 1236 pairs of lcm
- POJ - 1422 Air Raid(DAG的最小路径覆盖数)
- 分类算法之朴素贝叶斯分类(Naive Bayesian classification)
- larave 5 could not be opened: failed to open stream: Permission denied
- STL Container和ATL智能包裹类的冲突
- LightOJ 1021 Painful Base(状压DP)
- keystone中的domain
- 暴力 hihoCoder 1251 Today Is a Rainy Day (15北京C)
- AIDL使用方法记录