Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

class Solution { public: bool containsDuplicate(vector<int>& nums) { sort(nums.begin(), nums.end()); return unique(nums.begin(), nums.end()) != nums.end(); } };

Complexity: O(n log n + n)

Hi! This is my simple C++ solution using hash_set. Time complexity: O(n)

class Solution { public: bool containsDuplicate(vector<int>& nums) { unordered_set<int> hset; for(auto &v : nums) { if(hset.find(v) == hset.end()) hset.insert(v); else return true; } return false; } };

hset finding a element need time too.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.