705. Design HashSet

problem

solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class MyHashSet {
private:
vector<bool> vec;
public:
/** Initialize your data structure here. */
MyHashSet() {
vec = vector<bool>(1000001,false);
}

void add(int key) {
vec[key] = true;

}

void remove(int key) {
vec[key] = false;
}

/** Returns true if this set contains the specified element */
bool contains(int key) {
return vec[key]==true;
}
};

/**
* 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);
*/

`