Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 24e608d

Browse files
add 2335
1 parent 5663b52 commit 24e608d

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+
package com.fishercoder.solutions;
2+
3+
import java.util.PriorityQueue;
4+
5+
public class _2335 {
6+
public static class Solution1 {
7+
public int fillCups(int[] amount) {
8+
PriorityQueue<Integer> heap = new PriorityQueue<>((a, b) -> b - a);
9+
for (int num : amount) {
10+
if (num > 0) {
11+
heap.offer(num);
12+
}
13+
}
14+
int seconds = 0;
15+
while (!heap.isEmpty()) {
16+
if (heap.size() == 1) {
17+
seconds += heap.poll();
18+
return seconds;
19+
}
20+
int one = heap.poll();
21+
one--;
22+
if (!heap.isEmpty()) {
23+
int two = 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+
return seconds;
35+
}
36+
37+
}
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._2335;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
9+
public class _2335Test {
10+
private static _2335.Solution1 solution1;
11+
private static int[] amount;
12+
13+
@BeforeClass
14+
public static void setup() {
15+
solution1 = new _2335.Solution1();
16+
}
17+
18+
@Test
19+
public void test1() {
20+
amount = new int[]{5, 4, 4};
21+
assertEquals(7, solution1.fillCups(amount));
22+
}
23+
24+
@Test
25+
public void test2() {
26+
amount = new int[]{0, 0, 0};
27+
assertEquals(0, solution1.fillCups(amount));
28+
}
29+
30+
}

0 commit comments

Comments
 (0)