217. Contains Duplicate
如果一个数组里所有数都不同,则返回false
如果有重复数字,则返回true
C++(36ms):
1 class Solution { 2 public: 3 bool containsDuplicate(vector<int>& nums) { 4 int len1 = nums.size() ; 5 set<int> s(nums.begin() , nums.end()) ; 6 int len2 = s.size() ; 7 if (len1 == len2) 8 return false ; 9 else 10 return true ; 11 } 12 };