File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 280
280
| 1025 | [ Divisor Game] ( https://leetcode.com/problems/divisor-game ) | [ ![ Java] ( assets/java.png )] ( src/DivisorGame.java ) | |
281
281
| 1029 | [ Two City Scheduling] ( https://leetcode.com/problems/two-city-scheduling ) | | |
282
282
| 1030 | [ Matrix Cells in Distance Order] ( https://leetcode.com/problems/matrix-cells-in-distance-order ) | [ ![ Java] ( assets/java.png )] ( src/MatrixCellsInDistanceOrder.java ) | |
283
- | 1033 | [ Moving Stones Until Consecutive] ( https://leetcode.com/problems/moving-stones-until-consecutive ) | [ ![ Java ] ( assets/java.png )] ( src/ValidBoomerang.java ) | |
284
- | 1037 | [ Valid Boomerang] ( https://leetcode.com/problems/valid-boomerang ) | | |
283
+ | 1033 | [ Moving Stones Until Consecutive] ( https://leetcode.com/problems/moving-stones-until-consecutive ) | | |
284
+ | 1037 | [ Valid Boomerang] ( https://leetcode.com/problems/valid-boomerang ) | [ ![ Java ] ( assets/java.png )] ( src/ValidBoomerang.java ) | |
285
285
| 1042 | [ Flower Planting with no Adjacent] ( https://leetcode.com/problems/flower-planting-with-no-adjacent ) | | |
286
- | 1046 | [ Last Stone Weight] ( https://leetcode.com/problems/last-stone-weight ) | | |
286
+ | 1046 | [ Last Stone Weight] ( https://leetcode.com/problems/last-stone-weight ) | [ ![ Java ] ( assets/java.png )] ( src/LastStoneWeight.java ) | |
287
287
| 1047 | [ Remove All adjacent Duplicates in String] ( https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string ) | | |
288
288
| 1051 | [ Height Checker] ( https://leetcode.com/problems/height-checker ) | | |
289
289
| 1056 | [ Confusing Number] ( https://leetcode.com/problems/confusing-number ) | | |
Original file line number Diff line number Diff line change
1
+ import java .util .Comparator ;
2
+ import java .util .PriorityQueue ;
3
+ import java .util .Queue ;
4
+
5
+ public class LastStoneWeight {
6
+ public int lastStoneWeight (int [] stones ) {
7
+ Queue <Integer > maxHeap = new PriorityQueue <>(Comparator .reverseOrder ());
8
+ for (int stone : stones ) maxHeap .add (stone );
9
+ int stone1 , stone2 ;
10
+ while (maxHeap .size () > 1 ) {
11
+ stone1 = maxHeap .poll ();
12
+ stone2 = maxHeap .poll ();
13
+ if (stone1 != stone2 ) {
14
+ maxHeap .add (Math .abs (stone1 - stone2 ));
15
+ }
16
+ }
17
+ return maxHeap .isEmpty () ? 0 : maxHeap .peek ();
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments