2208. Minimum Operations to Halve Array Sum 發表於 2023-02-13 | 分類於 leetcode problemsolutionoption 1 - heap123456789101112131415161718192021class Solution {public: int halveArray(vector<int>& nums) { priority_queue<double> pq; double total = 0; for(int n:nums){ pq.push(n); total+=n; } int step = 0; double cur = total; while(cur > total/2.0){ double p = pq.top(); pq.pop(); p /= 2.0; cur -= p; pq.push(p); step++; } return step; }}; analysis time complexity O(nlogn) space complexity (n)