Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

217. Contains Duplicate

using namespace std;
#include <unordered_set>
#include <vector>
class Solution {
public:
  bool containsDuplicate(vector<int> &nums) {
    unordered_set<int> seen;
    for (int i : nums) {
      if (seen.count(i)) {
        return true;
      }
      seen.insert(i);
    }
    return false;
  }
};