Last stone weight
Easyheapsimulation
Each turn take the two heaviest stones x ≤ y and smash them: equal stones both vanish, otherwise one stone of weight y - x remains. Continue until at most one stone is left. Return its weight, or 0.
Example 1
Input: stones = [2,7,4,1,8,1] Output: 1
Example 2
Input: stones = [1] Output: 1
Constraints
- 1 ≤ stones.length ≤ 1000
- 1 ≤ stones[i] ≤ 1000
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {int[]} stones
* @return {int}
*/
function lastStoneWeight(stones) {
}