forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
45 lines (31 loc) · 784 Bytes
/
main.cpp
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
43
44
45
/// Source : https://leetcode.com/problems/design-hashset/description/
/// Author : liuyubobobo
/// Time : 2018-06-07
#include <iostream>
#include <set>
using namespace std;
#define N 100000
/// Using set(which is RBTree) to construct HashSet
/// Time Complexity: O(1)
/// Space Complexity: O(n)
class MyHashSet {
private:
set<int> data[N];
public:
/** Initialize your data structure here. */
MyHashSet() {
}
void add(int key) {
data[key % N].insert(key);
}
void remove(int key) {
data[key % N].erase(key);
}
/** Returns true if this set did not already contain the specified element */
bool contains(int key) {
return data[key % N].find(key) != data[key % N].end();
}
};
int main() {
return 0;
}