We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ad943dc + f1c2645 commit 3b1a917Copy full SHA for 3b1a917
1206. Design Skiplist (Hard)
@@ -0,0 +1,39 @@
1
+class Skiplist {
2
+public:
3
+
4
+ map<int,int>s;
5
6
+ Skiplist() {
7
8
+ }
9
10
+ bool search(int target) {
11
+ if(s.find(target)!=s.end())
12
+ return true;
13
+ else
14
+ return false;
15
16
17
+ void add(int num) {
18
+ s[num]++;
19
20
21
+ bool erase(int num) {
22
+ if(s.find(num)==s.end())
23
24
+ else{
25
+ s[num]--;
26
+ if(s[num]==0)
27
+ s.erase(num);
28
29
30
31
+};
32
33
+/**
34
+ * Your Skiplist object will be instantiated and called as such:
35
+ * Skiplist* obj = new Skiplist();
36
+ * bool param_1 = obj->search(target);
37
+ * obj->add(num);
38
+ * bool param_3 = obj->erase(num);
39
+ */
0 commit comments