- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1472.java
42 lines (35 loc) · 1.06 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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.List;
publicclass_1472 {
publicstaticclassSolution1 {
publicstaticclassBrowserHistory {
intcurr;
List<String> history;
publicBrowserHistory(Stringhomepage) {
history = newArrayList<>();
history.add(homepage);
curr = 0;
}
publicvoidvisit(Stringurl) {
curr++;
history = history.subList(0, curr);
history.add(url);
}
publicStringback(intsteps) {
curr -= steps;
if (curr < 0) {
curr = 0;
}
returnhistory.get(curr);
}
publicStringforward(intsteps) {
curr += steps;
if (history.size() <= curr) {
curr = history.size() - 1;
}
returnhistory.get(curr);
}
}
}
}