Skip to content

Commit 8ea4e2c

Browse files
authored
Create Solution.java
1 parent 38853f9 commit 8ea4e2c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int lastStoneWeight(int[] stones) {
3+
Queue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());
4+
for (int stone : stones) {
5+
queue.offer(stone);
6+
}
7+
while (queue.size() > 1) {
8+
int x = queue.poll();
9+
int y = queue.poll();
10+
if (x != y) {
11+
queue.offer(x - y);
12+
}
13+
}
14+
return queue.isEmpty() ? 0 : queue.poll();
15+
}
16+
}

0 commit comments

Comments
 (0)