From f1c2645ec82c35fe9597142f34ec57dd3e21510d Mon Sep 17 00:00:00 2001 From: Abhishek Gaurav Date: Mon, 10 Oct 2022 20:58:47 +0530 Subject: [PATCH] Create 1206. Design Skiplist (Hard) --- 1206. Design Skiplist (Hard) | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 1206. Design Skiplist (Hard) diff --git a/1206. Design Skiplist (Hard) b/1206. Design Skiplist (Hard) new file mode 100644 index 0000000..61ad7dd --- /dev/null +++ b/1206. Design Skiplist (Hard) @@ -0,0 +1,39 @@ +class Skiplist { +public: + + maps; + + Skiplist() { + + } + + bool search(int target) { + if(s.find(target)!=s.end()) + return true; + else + return false; + } + + void add(int num) { + s[num]++; + } + + bool erase(int num) { + if(s.find(num)==s.end()) + return false; + else{ + s[num]--; + if(s[num]==0) + s.erase(num); + return true; + } + } +}; + +/** + * Your Skiplist object will be instantiated and called as such: + * Skiplist* obj = new Skiplist(); + * bool param_1 = obj->search(target); + * obj->add(num); + * bool param_3 = obj->erase(num); + */