Leetcode Problem 1206. Design Skiplist

1206. Design Skiplist

Leetcode Solutions

Implementing a Skiplist with Linked Lists

  1. Initialize the Skiplist with a head node that has pointers to all levels.
  2. For search(target), start from the top level and move right until the next node's value is greater than target, then go down one level and continue until the bottom level is reached. Return true if target is found, false otherwise.
  3. For add(num), perform a similar traversal as search but keep track of the predecessors at each level. Insert num after the predecessors, randomly deciding whether to insert it at higher levels.
  4. For erase(num), again traverse the list to find num, and remove it by adjusting pointers at each level where it appears.
UML Thumbnail

Skiplist Implementation Using ArrayList and Binary Search

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...