Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit30f2171

Browse files
authored
Create Minimum Operations to Exceed Threshold Value II.java
1 parent2daac9d commit30f2171

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+
classSolution {
2+
publicintminOperations(int[]nums,intk) {
3+
PriorityQueue<Long>pq =newPriorityQueue<>();
4+
for (intnum :nums) {
5+
pq.add((long)num);
6+
}
7+
intoperations =0;
8+
while (pq.peek() <k) {
9+
longsmallest =pq.poll();
10+
longsecondSmallest =pq.poll();
11+
longnewValue =Math.min(smallest,secondSmallest) *2 +Math.max(smallest,secondSmallest);
12+
pq.add(newValue);
13+
operations++;
14+
}
15+
returnoperations;
16+
}
17+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp