Skip to content

Commit ece5cc7

Browse files
committed
Time: 4 ms (16.55%), Space: 45.4 MB (7.02%) - LeetHub
1 parent 83d5792 commit ece5cc7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public int[] getFinalState(int[] nums, int k, int multiplier) {
3+
// PQ
4+
// TC : O(nlogn+klogn)
5+
// SC :O(n)
6+
7+
PriorityQueue<int[]> pq = new PriorityQueue<>((a,b)->(a[0]==b[0] ? a[1]-b[1] : a[0]-b[0]));
8+
for(int i=0;i<nums.length;i++){
9+
pq.offer(new int[]{nums[i],i});
10+
}
11+
while(k-->0){
12+
int[] pp = pq.poll();
13+
pp[0]*=multiplier;
14+
pq.offer(pp);
15+
}
16+
int[] res = new int[nums.length];
17+
while(!pq.isEmpty()){
18+
int[] pair = pq.poll();
19+
res[pair[1]] = pair[0];
20+
}
21+
return res;
22+
}
23+
}

0 commit comments

Comments
 (0)