Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commite67e2f1

Browse files
add 1472
1 parent532fba0 commite67e2f1

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ _If you like this project, please leave me a star._ ★
276276
|1476|[Subrectangle Queries](https://leetcode.com/problems/subrectangle-queries/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1476.java)||Medium|Array|
277277
|1475|[Final Prices With a Special Discount in a Shop](https://leetcode.com/problems/final-prices-with-a-special-discount-in-a-shop/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1475.java)||Easy|Array|
278278
|1474|[Delete N Nodes After M Nodes of a Linked List](https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1474.java)||Easy|LinkedList|
279+
|1472|[Design Browser History](https://leetcode.com/problems/design-browser-history/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1472.java)||Medium|Array, Design|
279280
|1471|[The k Strongest Values in an Array](https://leetcode.com/problems/the-k-strongest-values-in-an-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1471.java)||Medium|Array, Sort|
280281
|1470|[Shuffle the Array](https://leetcode.com/problems/shuffle-the-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1470.java),[C++](../master/cpp/_1470.cpp)||Easy|Array|
281282
|1469|[Find All The Lonely Nodes](https://leetcode.com/problems/find-all-the-lonely-nodes/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1469.java)||Easy|Tree, DFS|
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.ArrayList;
4+
importjava.util.List;
5+
6+
publicclass_1472 {
7+
publicstaticclassSolution1 {
8+
publicstaticclassBrowserHistory {
9+
10+
intcurr;
11+
List<String>history;
12+
13+
publicBrowserHistory(Stringhomepage) {
14+
history =newArrayList<>();
15+
history.add(homepage);
16+
curr =0;
17+
}
18+
19+
publicvoidvisit(Stringurl) {
20+
curr++;
21+
history =history.subList(0,curr);
22+
history.add(url);
23+
}
24+
25+
publicStringback(intsteps) {
26+
curr -=steps;
27+
if (curr <0) {
28+
curr =0;
29+
}
30+
returnhistory.get(curr);
31+
}
32+
33+
publicStringforward(intsteps) {
34+
curr +=steps;
35+
if (history.size() <=curr) {
36+
curr =history.size() -1;
37+
}
38+
returnhistory.get(curr);
39+
}
40+
}
41+
42+
}
43+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1472;
4+
importorg.junit.Test;
5+
6+
importstaticorg.junit.Assert.assertEquals;
7+
8+
publicclass_1472Test {
9+
privatestatic_1472.Solution1.BrowserHistorybrowserHistory;
10+
11+
@Test
12+
publicvoidtest1() {
13+
browserHistory =new_1472.Solution1.BrowserHistory("leetcode.com");
14+
browserHistory.visit("google.com");
15+
browserHistory.visit("facebook.com");
16+
browserHistory.visit("youtube.com");
17+
assertEquals("facebook.com",browserHistory.back(1));
18+
assertEquals("google.com",browserHistory.back(1));
19+
assertEquals("facebook.com",browserHistory.forward(1));
20+
browserHistory.visit("linkedin.com");
21+
assertEquals("linkedin.com",browserHistory.forward(2));
22+
assertEquals("google.com",browserHistory.back(2));
23+
assertEquals("leetcode.com",browserHistory.back(7));
24+
}
25+
26+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp