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;
}
};
class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
return(len(set(nums)) != len(nums))
-> Castt a set on list is O(n) and a len is O(1) and len(nums) is O(n) in time
-> In memory it doesn’t allocate anything.