Skip to content

Commit 30f2171

Browse files
authored
Create Minimum Operations to Exceed Threshold Value II.java
1 parent 2daac9d commit 30f2171

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int minOperations(int[] nums, int k) {
3+
PriorityQueue<Long> pq = new PriorityQueue<>();
4+
for (int num : nums) {
5+
pq.add((long) num);
6+
}
7+
int operations = 0;
8+
while (pq.peek() < k) {
9+
long smallest = pq.poll();
10+
long secondSmallest = pq.poll();
11+
long newValue = Math.min(smallest, secondSmallest) * 2 + Math.max(smallest, secondSmallest);
12+
pq.add(newValue);
13+
operations++;
14+
}
15+
return operations;
16+
}
17+
}

0 commit comments

Comments
 (0)