Skip to content

Commit a14f47a

Browse files
authored
Update Last Stone Weight.java
1 parent 1bf1b99 commit a14f47a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Easy/Last Stone Weight.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
class Solution {
22
public int lastStoneWeight(int[] stones) {
3-
PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> b - a);
3+
PriorityQueue<Integer> pq = new PriorityQueue<>((o1, o2) -> o2 - o1);
44
for (int stone : stones) {
55
pq.add(stone);
66
}
77
while (pq.size() > 1) {
8-
int max1 = pq.poll();
9-
int max2 = pq.poll();
10-
if (max1 != max2) {
11-
pq.add(max1 - max2);
8+
int firstStone = pq.poll();
9+
int secondStone = pq.poll();
10+
if (firstStone != secondStone) {
11+
pq.add(firstStone - secondStone);
1212
}
1313
}
14-
return pq.isEmpty() ? 0 : pq.peek();
14+
return pq.isEmpty() ? 0 : pq.poll();
1515
}
1616
}

0 commit comments

Comments
 (0)