classMyHashSet{public:/** Initialize your data structure here. */constint BASE =769;
vector<list<int>> data = vector<list<int>>(769);intgetHashCode(int key){return key % BASE;}MyHashSet(){}voidadd(int key){int hash_code =getHashCode(key);for(auto it = data[hash_code].begin(); it != data[hash_code].end(); it++){if(*it == key)return;}
data[hash_code].push_back(key);}voidremove(int key){int hash_code =getHashCode(key);for(auto it = data[hash_code].begin(); it != data[hash_code].end(); it++){if(*it == key){
data[hash_code].erase(it);return;}}}/** Returns true if this set contains the specified element */boolcontains(int key){int hash_code =getHashCode(key);for(auto it = data[hash_code].begin(); it != data[hash_code].end(); it++){if(*it == key)returntrue;}returnfalse;}};/**
* Your MyHashSet object will be instantiated and called as such:
* MyHashSet* obj = new MyHashSet();
* obj->add(key);
* obj->remove(key);
* bool param_3 = obj->contains(key);
*/
classMyHashSet{public:/** Initialize your data structure here. */
vector<bool> HashSet = vector<bool>(1e6+1,false);MyHashSet(){}voidadd(int key){
HashSet[key]=true;}voidremove(int key){
HashSet[key]=false;}/** Returns true if this set contains the specified element */boolcontains(int key){return HashSet[key];}};/**
* Your MyHashSet object will be instantiated and called as such:
* MyHashSet* obj = new MyHashSet();
* obj->add(key);
* obj->remove(key);
* bool param_3 = obj->contains(key);
*/