[C++/Python] Stack and Two Pointers (C++ can be more concise than Python!)
c++. The = operator in c++ returning a reference works perfectly here!.\n\nclass BrowserHistory {\npublic:\n    string stack[5005];\n    int p, t;\t// current p
c++. The `=` operator in c++ returning a reference works perfectly here!.\n```\nclass BrowserHistory {\npublic:\n    string stack[5005];\n    int p, t;\t// current pointer, stack\'s top\n    \n    BrowserHistory(string homepage) {\n        stack[p = t = 0] = homepage;\n    }\n    \n    void visit(string url) {\n        stack[t = ++p] = url;\n    }\n    \n    string back(int steps) {\n        return stack[p = max(0, p-steps)];\n    }\n    \n    string forward(int steps) {\n        return stack[p = min(t, p+steps)];\n    }\n};\n```\nPython\n```\nclass BrowserHistory:\n\n    def __init__(self, homepage: str):\n        self.stack = [""] * 5005\n        self.p = self.t = 0\n        self.stack[0] = homepage\n        \n    def visit(self, url: str) -> None:\n        self.p += 1\n        self.stack[self.p] = url\n        self.t = self.p\n\n    def back(self, steps: int) -> str:\n        self.p = max(0, self.p-steps)\n        return self.stack[self.p]\n        \n    def forward(self, steps: int) -> str:\n        self.p = min(self.t, self.p + steps)\n        return self.stack[self.p]\n```
['C']