lcpBi125

方法一:遍历

1
2
3
4
5
6
7
8
9
class Solution {
public int minOperations(int[] nums, int k) {
int res = 0;
for (int x : nums)
if (x < k)
++res;
return res;
}
}

方法一:小根堆

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public int minOperations(int[] nums, int k) {
int res = 0;
PriorityQueue<Long> queue = new PriorityQueue();
for (int x : nums)
queue.add((long) x);
while (true) {
long x = queue.poll();
if (x >= k)
return res;
long y = queue.poll();
queue.add(x * 2 + y);
++res;
}
}
}

方法一:

方法一:


lcpBi125
https://leopol1d.github.io/2024/03/03/lcpBi125/
作者
Leopold
发布于
2024年3月3日
许可协议