forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0705.cpp
More file actions
42 lines (28 loc) · 931 Bytes
/
0705.cpp
File metadata and controls
42 lines (28 loc) · 931 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
class MyHashSet {
public:
vector<int> shit;
/** Initialize your data structure here. */
MyHashSet() {
}
void add(int key) {
if(find(shit.begin(), shit.end(), key) == shit.end())
shit.push_back(key);
}
void remove(int key) {
if(count(shit.begin(), shit.end(), key) > 0){
int temp = find(shit.begin(), shit.end(), key) - shit.begin();
shit.erase(shit.begin() + temp);
}
}
/** Returns true if this set contains the specified element */
bool contains(int key) {
return find(shit.begin(), shit.end(), key) != shit.end();
}
};
/**
* 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);
*/