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

Commit027efb4

Browse files
add 895
1 parent8f2c21f commit027efb4

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ _If you like this project, please leave me a star._ ★
387387
|900|[RLE Iterator](https://leetcode.com/problems/rle-iterator/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_900.java)||Medium|
388388
|897|[Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_897.java) | |Easy| DFS, recursion
389389
|896|[Monotonic Array](https://leetcode.com/problems/monotonic-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_896.java)||Easy|
390+
|895|[Maximum Frequency Stack](https://leetcode.com/problems/maximum-frequency-stack/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_895.java)| HashTable, Stack|Hard|
390391
|890|[Find and Replace Pattern](https://leetcode.com/problems/find-and-replace-pattern/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_890.java)||Medium|
391392
|893|[Groups of Special-Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_893.java)|[:tv:](https://youtu.be/tbtXPKkA2Zw)|Easy|
392393
|888|[Fair Candy Swap](https://leetcode.com/problems/fair-candy-swap/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_888.java)||Easy|
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.HashMap;
4+
importjava.util.Map;
5+
importjava.util.PriorityQueue;
6+
7+
publicclass_895 {
8+
publicstaticclassSolution1 {
9+
publicstaticclassFreqStack {
10+
intcounter;
11+
PriorityQueue<int[]>maxHeap;
12+
Map<Integer,Integer>map;
13+
14+
publicFreqStack() {
15+
maxHeap =newPriorityQueue<>((a,b) ->a[1] !=b[1] ?b[1] -a[1] :b[2] -a[2]);
16+
map =newHashMap<>();
17+
}
18+
19+
publicvoidpush(intx) {
20+
map.put(x,map.getOrDefault(x,0) +1);
21+
maxHeap.offer(newint[]{x,map.get(x),counter++});
22+
}
23+
24+
publicintpop() {
25+
int[]top =maxHeap.poll();
26+
map.put(top[0],map.get(top[0]) -1);
27+
returntop[0];
28+
}
29+
}
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._895;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticjunit.framework.Assert.assertEquals;
8+
9+
publicclass_895Test {
10+
11+
privatestatic_895.Solution1.FreqStackfreqStack;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
freqStack =new_895.Solution1.FreqStack();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
freqStack.push(5);
21+
freqStack.push(7);
22+
freqStack.push(5);
23+
freqStack.push(7);
24+
freqStack.push(4);
25+
freqStack.push(5);
26+
assertEquals(5,freqStack.pop());
27+
assertEquals(7,freqStack.pop());
28+
assertEquals(5,freqStack.pop());
29+
assertEquals(4,freqStack.pop());
30+
}
31+
32+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp