Design Skiplist LeetCode solution in C++

1
class Skiplist {
2
public:
3
map<int, int> s;
4
Skiplist() {}
5

6
bool search(int target) {
7
if (s.find(target) != s.end())
8
return true;
9
else
10
return false;
11
}
12

13
void add(int num) {
14
s[num]++;
15
}
16

17
bool erase(int num) {
18
if (s.find(num) == s.end())
19
return false;
20
else {
21
s[num]--;
22
if (s[num] == 0) s.erase(num);
23
return true;
24
}
25
}
26
};
27

28
/**
29
* Your Skiplist object will be instantiated and called as such:
30
* Skiplist* obj = new Skiplist();
31
* bool param_1 = obj->search(target);
32
* obj->add(num);
33
* bool param_3 = obj->erase(num);
34
*/

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0