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

Commit 7acc434

Browse files
add 2208
1 parent e5d44fe commit 7acc434

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ _If you like this project, please leave me a star._ ★
99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|-------------|-------------
1111
| 2210 |[Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2210.java) || Easy ||
12+
| 2208 |[Minimum Operations to Halve Array Sum](https://leetcode.com/problems/minimum-operations-to-halve-array-sum/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2208.java) || Medium ||
1213
| 2201 |[Count Artifacts That Can Be Extracted](https://leetcode.com/problems/count-artifacts-that-can-be-extracted/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2201.java) || Medium ||
1314
| 2200 |[Find All K-Distant Indices in an Array](https://leetcode.com/problems/find-all-k-distant-indices-in-an-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2200.java) || Easy ||
1415
| 2194 |[Cells in a Range on an Excel Sheet](https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2194.java) || Easy ||
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.PriorityQueue;
4+
5+
public class _2208 {
6+
public static class Solution1 {
7+
public int halveArray(int[] nums) {
8+
PriorityQueue<Double> heap = new PriorityQueue<>((a, b) -> Double.compare(b, a));
9+
double sum = 0;
10+
for (int num : nums) {
11+
heap.offer(Double.valueOf(num));
12+
sum += num;
13+
}
14+
double half = (double) sum / 2;
15+
int ops = 0;
16+
while (sum > half) {
17+
Double max = heap.poll();
18+
sum -= max;
19+
double h = max / 2;
20+
sum += h;
21+
heap.offer(h);
22+
ops++;
23+
}
24+
return ops;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)