---
# System prepended metadata

title: 2208. Minimum Operations to Halve Array Sum
tags: [Leetcode, Medium, Greedy]

---

# 2208. Minimum Operations to Halve Array Sum
###### tags: `Leetcode` `Medium` `Greedy`
Link: https://leetcode.com/problems/minimum-operations-to-halve-array-sum/description/
## 思路
greedy
每次把最大的number 取half
## Code
```java=
class Solution {
    public int halveArray(int[] nums) {
        double sum = 0.0;
        
        Queue<Double> pq = new PriorityQueue<>(Collections.reverseOrder());
        for(int num:nums){
            sum += num;
            pq.add(num*1.0);
        }
        double curr = sum;
        int ans = 0;
        while(curr>sum/2){
            double max = pq.poll();
            curr -= max/2;
            pq.add(max/2);
            ans++;
        }
        return ans;
    }
}
```