- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1046.java
25 lines (23 loc) · 742 Bytes
/
_1046.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
packagecom.fishercoder.solutions.secondthousand;
importjava.util.PriorityQueue;
publicclass_1046 {
publicstaticclassSolution1 {
publicintlastStoneWeight(int[] stones) {
PriorityQueue<Integer> heap = newPriorityQueue<>((a, b) -> b - a);
for (intstone : stones) {
heap.offer(stone);
}
while (!heap.isEmpty()) {
if (heap.size() >= 2) {
intone = heap.poll();
inttwo = heap.poll();
intdiff = one - two;
heap.offer(diff);
} else {
returnheap.poll();
}
}
return -1;
}
}
}