Leetcode Problem 1472. Design Browser History

1472. Design Browser History

Leetcode Solutions

Approach: Two Stacks

  1. Initialize history and future stacks and a current URL variable.
  2. For visit(url), push current to history, set current to url, and clear future.
  3. For back(steps), pop from history and push to future until steps are decremented to 0 or history is empty, then update current.
  4. For forward(steps), pop from future and push to history until steps are decremented to 0 or future is empty, then update current.
UML Thumbnail

Approach: Doubly Linked List

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...