题目:
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.
分析:
查找是否有重复元素,那么可以利用set来完成这道题目。
代码:
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
return set<int>(nums.begin(),nums.end()).size()<nums.size();
}
};