leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0217.cpp (452B)


      1 class Solution {
      2   public:
      3     bool containsDuplicate(vector<int> &nums) {
      4         unordered_set<int> us;
      5         for (int n : nums)
      6             if (us.count(n))
      7                 return true;
      8             else
      9                 us.insert(n);
     10         return false;
     11     }
     12 };
     13 
     14 // Fun oneliner
     15 class Solution {
     16   public:
     17     bool containsDuplicate(vector<int> &nums) {
     18         return nums.size() > unordered_set<int>(nums.begin(), nums.end()).size();
     19     }
     20 };