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; } } }
|