[Java/Python 3] Use List and two pointers
Use  List to store history; Use cur and end to record the current and the end of history indices. -- credit to @fighting_for_flag.\n\njava\n    private List<Str
Use  `List` to store history; Use `cur` and `end` to record the current and the end of history indices. -- credit to **@fighting_for_flag**.\n\n```java\n    private List<String> history = new ArrayList<>();\n    private int cur, end;\n    \n    public BrowserHistory(String homepage) {\n        history.add(homepage);\n    }\n    \n    public void visit(String url) {\n        if (++cur < history.size()) {\n            history.set(cur, url);\n        }else {\n            history.add(url);\n        }\n        end = cur;\n    }\n    \n    public String back(int steps) {\n        cur = Math.max(0, cur - steps);\n        return history.get(cur);\n    }\n    \n    public String forward(int steps) {\n        cur = Math.min(end, cur + steps);\n        return history.get(cur);\n    }\n```\n```python\n    def __init__(self, homepage: str):\n        self.history = [homepage]\n        self.cur = self.end = 0\n    def visit(self, url: str) -> None:\n        self.cur += 1\n        if self.cur < len(self.history):\n            self.history[self.cur] = url\n        else:\n            self.history.append(url)\n        self.end = self.cur\n        \n    def back(self, steps: int) -> str:\n        self.cur = max(0, self.cur - steps)\n        return self.history[self.cur]    \n\n    def forward(self, steps: int) -> str:\n        self.cur = min(self.end, self.cur + steps)\n        return self.history[self.cur]\n```
[]