Skip to content

Latest commit

 

History

History
54 lines (38 loc) · 1.46 KB

_1472. Design Browser History.md

File metadata and controls

54 lines (38 loc) · 1.46 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 06, 2024

Last updated : July 06, 2024


Related Topics : Array, Linked List, Stack, Design, Doubly-Linked List, Data Stream

Acceptance Rate : 77.7 %


Solutions

Python

class BrowserHistory:

    def __init__(self, homepage: str):
        self.history = [homepage]
        self.spot = 0

    def visit(self, url: str) -> None:
        self.spot += 1
        if self.spot < len(self.history) :
            self.history = self.history[:self.spot]
        self.history.append(url)

    def back(self, steps: int) -> str:
        self.spot = max(0, self.spot - steps)
        return self.history[self.spot]

    def forward(self, steps: int) -> str:
        self.spot = min(len(self.history) - 1, self.spot + steps)
        return self.history[self.spot]


# Your BrowserHistory object will be instantiated and called as such:
# obj = BrowserHistory(homepage)
# obj.visit(url)
# param_2 = obj.back(steps)
# param_3 = obj.forward(steps)