Skip to content

Commit d4478d7

Browse files
authored
Create 3066. Minimum Operations to Exceed Threshold Value II (#714)
2 parents 285520a + 5800a0f commit d4478d7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int minOperations(vector<int>& nums, int k) {
4+
priority_queue<long long, vector<long long>, greater<long long>> pq;
5+
for (auto& num : nums) {
6+
pq.push(num);
7+
}
8+
9+
int minOp = 0;
10+
while (pq.size() >= 2 && pq.top() < k) {
11+
long long x = pq.top();
12+
pq.pop();
13+
long long y = pq.top();
14+
pq.pop();
15+
long long z = x * 2 + y;
16+
pq.push(z);
17+
minOp++;
18+
}
19+
20+
return minOp;
21+
}
22+
};

0 commit comments

Comments
 (0)