Maximum Product After K Increments LeetCode solution in Java

1
class Solution {
2
public int maximumProduct(int[] nums, int k) {
3

4
Queue<Integer> pq = new PriorityQueue<>();
5
for (int num : nums) pq.add(num);
6

7
while (k-- > 0) {
8
int top = pq.poll() + 1;
9
pq.add(top);
10
}
11

12
long res = 1;
13
while (!pq.isEmpty()) {
14
res = (res * pq.poll()) % 1000000007;
15
}
16

17
return (int) (res);
18
}
19
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0