Contains Duplicate leetcode

时间:2021-11-01 16:32:16

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

bool containsDuplicate(vector<int>& nums) {
unordered_map<int, int> hash;
for (auto i : nums)
{
if (hash.find(i) == hash.end())
hash.insert(make_pair(i, ));
else
return true;
}
return false;
}