标签:leetcode
链接:https://leetcode.com/problems/contains-duplicate/
问题描述:
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.
Hide Tags Array Hash Table
如果给出数组中有重复元素则返回true否则返回false;
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
map<int,int> hm;
for(int i=0;i<nums.size();i++)
{
if(hm.find(nums[i])!=hm.end())
return true;
hm[nums[i]]=1;
}
return false;
}
};
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:leetcode
原文地址:http://blog.csdn.net/efergrehbtrj/article/details/46822431