forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_1472.java
43 lines (35 loc) · 1.05 KB
/
_1472.java
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
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.List;
public class _1472 {
public static class Solution1 {
public static class BrowserHistory {
int curr;
List<String> history;
public BrowserHistory(String homepage) {
history = new ArrayList<>();
history.add(homepage);
curr = 0;
}
public void visit(String url) {
curr++;
history = history.subList(0, curr);
history.add(url);
}
public String back(int steps) {
curr -= steps;
if (curr < 0) {
curr = 0;
}
return history.get(curr);
}
public String forward(int steps) {
curr += steps;
if (history.size() <= curr) {
curr = history.size() - 1;
}
return history.get(curr);
}
}
}
}