# 1472. Design Browser History

{% embed url="<https://leetcode.com/problems/design-browser-history/>" %}

周赛题啊...做的时候就感觉不知道medium在哪里，挺简单一道 design 题。

```python
class BrowserHistory:

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

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

    def back(self, steps: int) -> str:
        validSteps = min(self.pointer, steps)
        self.pointer -= validSteps
        return self.history[self.pointer]

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