Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
33 lines (28 loc) · 818 Bytes

File metadata and controls

33 lines (28 loc) · 818 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package problems;
import java.util.Deque;
import java.util.LinkedList;
public class LeetCode1472 {
// 后退栈:存放历史页面(后退页面)和当前页面
Deque<String> s1 = new LinkedList<>();
// 前进栈:存放未来页面(前进页面)
Deque<String> s2 = new LinkedList<>();
public LeetCode1472(String homepage) {
s1.push(homepage);
}
public void visit(String url) {
s1.push(url);
s2.clear();
}
public String back(int steps) {
for (int i = 0; i < steps && s1.size() > 1; i++) {
s2.push(s1.pop());
}
return s1.peek();
}
public String forward(int steps) {
for (int i = 0; i < steps && !s2.isEmpty(); i++) {
s1.push(s2.pop());
}
return s1.peek();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.