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的性质就行了
1 class Solution { 2 public: 3 bool containsDuplicate(vector<int>& nums) { 4 if(nums.empty()) 5 return false; 6 7 set<int> s(nums.begin(), nums.end()); 8 9 return s.size() < nums.size() ? true : false; 10 11 } 12 };