-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
50 lines (43 loc) · 886 Bytes
/
Copy pathSolution.java
File metadata and controls
50 lines (43 loc) · 886 Bytes
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
47
48
49
50
class BrowserHistory
{
Node root;
Node current;
public BrowserHistory(String homepage)
{
root = new Node(homepage);
current = root;
}
public void visit(String url)
{
final Node node = new Node(url);
current.next = node;
node.prev = current;
current = node;
}
public String back(int steps)
{
while (current.prev != null && steps-- > 0)
{
current = current.prev;
}
return current.url;
}
public String forward(int steps)
{
while (current.next != null && steps-- > 0)
{
current = current.next;
}
return current.url;
}
class Node
{
private final String url;
Node prev;
Node next;
Node(String url)
{
this.url = url;
}
}
}