|
2 | 2 |
|
3 | 3 | importjava.util.PriorityQueue;
|
4 | 4 |
|
5 |
| -/** |
6 |
| - * 1046. Last Stone Weight |
7 |
| - * |
8 |
| - * We have a collection of rocks, each rock has a positive integer weight. |
9 |
| - * |
10 |
| - * Each turn, we choose the two heaviest rocks and smash them together. |
11 |
| - * Suppose the stones have weights x and y with x <= y. The result of this smash is: |
12 |
| - * |
13 |
| - * If x == y, both stones are totally destroyed; |
14 |
| - * If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x. |
15 |
| - * At the end, there is at most 1 stone left. Return the weight of this stone (or 0 if there are no stones left.) |
16 |
| - * |
17 |
| - * Example 1: |
18 |
| - * Input: [2,7,4,1,8,1] |
19 |
| - * Output: 1 |
20 |
| - * Explanation: |
21 |
| - * We combine 7 and 8 to get 1 so the array converts to [2,4,1,1,1] then, |
22 |
| - * we combine 2 and 4 to get 2 so the array converts to [2,1,1,1] then, |
23 |
| - * we combine 2 and 1 to get 1 so the array converts to [1,1,1] then, |
24 |
| - * we combine 1 and 1 to get 0 so the array converts to [1] then that's the value of last stone. |
25 |
| - * |
26 |
| - * Note: |
27 |
| - * 1 <= stones.length <= 30 |
28 |
| - * 1 <= stones[i] <= 1000 |
29 |
| - * */ |
30 | 5 | publicclass_1046 {
|
31 | 6 | publicstaticclassSolution1 {
|
32 | 7 | publicintlastStoneWeight(int[]stones) {
|
|