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

Commit24e608d

Browse files
add 2335
1 parent5663b52 commit24e608d

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11-
| 2331|[Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2331.java)|| Easy||
11+
| 2335|[Minimum Amount of Time to Fill Cups](https://leetcode.com/problems/minimum-amount-of-time-to-fill-cups/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2335.java)|| Easy||
12+
| 2331|[Evaluate Boolean Binary Tree](https://leetcode.com/problems/evaluate-boolean-binary-tree/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2331.java)|| Easy||
1213
| 2326|[Spiral Matrix IV](https://leetcode.com/problems/spiral-matrix-iv/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2326.java)|| Medium||
1314
| 2325|[Decode the Message](https://leetcode.com/problems/decode-the-message/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2325.java)|| Easy||
1415
| 2319|[Check if Matrix Is X-Matrix](https://leetcode.com/problems/check-if-matrix-is-x-matrix/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2319.java)|| Easy||
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.PriorityQueue;
4+
5+
publicclass_2335 {
6+
publicstaticclassSolution1 {
7+
publicintfillCups(int[]amount) {
8+
PriorityQueue<Integer>heap =newPriorityQueue<>((a,b) ->b -a);
9+
for (intnum :amount) {
10+
if (num >0) {
11+
heap.offer(num);
12+
}
13+
}
14+
intseconds =0;
15+
while (!heap.isEmpty()) {
16+
if (heap.size() ==1) {
17+
seconds +=heap.poll();
18+
returnseconds;
19+
}
20+
intone =heap.poll();
21+
one--;
22+
if (!heap.isEmpty()) {
23+
inttwo =heap.poll();
24+
two--;
25+
if (two >0) {
26+
heap.offer(two);
27+
}
28+
}
29+
if (one >0) {
30+
heap.offer(one);
31+
}
32+
seconds++;
33+
}
34+
returnseconds;
35+
}
36+
37+
}
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._2335;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_2335Test {
10+
privatestatic_2335.Solution1solution1;
11+
privatestaticint[]amount;
12+
13+
@BeforeClass
14+
publicstaticvoidsetup() {
15+
solution1 =new_2335.Solution1();
16+
}
17+
18+
@Test
19+
publicvoidtest1() {
20+
amount =newint[]{5,4,4};
21+
assertEquals(7,solution1.fillCups(amount));
22+
}
23+
24+
@Test
25+
publicvoidtest2() {
26+
amount =newint[]{0,0,0};
27+
assertEquals(0,solution1.fillCups(amount));
28+
}
29+
30+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp