-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1472_Design_Browser_History.py
More file actions
46 lines (37 loc) · 1.05 KB
/
Copy path1472_Design_Browser_History.py
File metadata and controls
46 lines (37 loc) · 1.05 KB
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
41
42
43
44
45
46
class Node:
val = ""
next = None
prev = None
def __init__(self, val: str):
self.val = val
class BrowserHistory:
cur = None
def __init__(self, homepage: str):
newNode = Node(homepage)
self.cur = newNode
def visit(self, url: str) -> None:
newNode = Node(url)
self.cur.next = newNode
newNode.prev = self.cur
self.cur = newNode
def back(self, steps: int) -> str:
i = 0
while(i < steps):
if self.cur.prev == None:
return self.cur.val
self.cur = self.cur.prev
i += 1
return self.cur.val
def forward(self, steps: int) -> str:
i = 0
while(i < steps):
if self.cur.next == None:
return self.cur.val
self.cur = self.cur.next
i += 1
return self.cur.val
# 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)