1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| class BrowserHistory:
def __init__(self, homepage: str):
self.head = Node(homepage)
self.current = self.head
def visit(self, url: str) -> None:
self.current.next = Node(url,back = self.current)
self.current = self.current.next
def back(self, steps: int) -> str:
while steps > 0 and self.current.back != None:
steps -= 1
self.current = self.current.back
return self.current.data
def forward(self, steps: int) -> str:
while steps > 0 and self.current.next != None:
steps -= 1
self.current = self.current.next
return self.current.data
class Node:
def __init__(self,data,next = None,back = None):
self.data = data
self.next = next
self.back = back
# 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)
|