Skip to content

Commit f1c2645

Browse files
Create 1206. Design Skiplist (Hard)
1 parent f66f0ab commit f1c2645

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

1206. Design Skiplist (Hard)

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
return false;
24+
else{
25+
s[num]--;
26+
if(s[num]==0)
27+
s.erase(num);
28+
return true;
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

Comments
 (0)