We’re preparing your current view and syncing the latest data.
You are given an array stones where stones[i] is the weight of the i-th stone. We are playing a game with the stones. On each turn, we choose the two heaviest stones and smash them together. Suppose the heaviest stones have weights x and y with x <= y. The result of this smash is:
An integer array stones representing the weights of the stones.
An integer representing the weight of the last remaining stone or 0 if none remain.
1 <= stones.length <= 30 1 <= stones[i] <= 1000
Example 1
Input
[2,7,4,1,8,1]
Output
1
Explanation
We combine stones (8,7) -> 1, then (4,2) -> 2, heap becomes [2,1,1,1]. Next (2,1) -> 1, heap is [1,1,1]. Next (1,1) -> 0, heap [1]. Last stone weight is 1.