Make Array Zero by Subtracting Equal Amounts LeetCode solution in C++

1
class Solution {
2
public:
3
int minimumOperations(vector<int> &nums) {
4
priority_queue<int, vector<int>, greater<int>> pq;
5

6
for (int i = 0; i < nums.size(); i++) pq.push(nums[i]);
7

8
int curr_min = 0;
9
int count = 0;
10

11
while (!pq.empty()) {
12
if (pq.top() == 0)
13
pq.pop();
14
else {
15
int top = pq.top() - curr_min;
16
if (top != 0) {
17
curr_min += top;
18
count++;
19
}
20
pq.pop();
21
}
22
}
23
return count;
24
}
25
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0