Java || Doubly Linked List || 45ms || beats 90%
\n\n\tclass ListNode {\n\n\t\tString url;\n\t\tListNode next;\n\t\tListNode prev;\n\n\t\tpublic ListNode(String url) {\n\t\t\tthis.url = url;\n\t\t\tthis.next =
\n\n\tclass ListNode {\n\n\t\tString url;\n\t\tListNode next;\n\t\tListNode prev;\n\n\t\tpublic ListNode(String url) {\n\t\t\tthis.url = url;\n\t\t\tthis.next = null;\n\t\t\tthis.prev = null;\n\t\t}\n\t}\n\n\tclass BrowserHistory {\n\n\t\tListNode curr;\n\n\t\t// O(1)\n\t\tpublic BrowserHistory(String homepage) {\n\t\t\tcurr = new ListNode(homepage);\n\t\t}\n\n\t\t// O(1)\n\t\tpublic void visit(String url) {\n\t\t\tListNode temp = new ListNode(url);\n\t\t\tcurr.next = temp;\n\t\t\ttemp.prev = curr;\n\t\t\tcurr = temp;\n\t\t}\n\n\t\t// O(steps)\n\t\tpublic String back(int steps) {\n\t\t\twhile (curr.prev != null && steps >= 1) {\n\t\t\t\tcurr = curr.prev;\n\t\t\t\tsteps--;\n\t\t\t}\n\t\t\treturn curr.url;\n\t\t}\n\n\t\t// O(steps)\n\t\tpublic String forward(int steps) {\n\t\t\twhile (curr.next != null && steps >= 1) {\n\t\t\t\tcurr = curr.next;\n\t\t\t\tsteps--;\n\t\t\t}\n\t\t\treturn curr.url;\n\t\t}\n\t}
[]