You are given an array of integers stones where stones[i] is the weight of the ith stone.
We play a game with the stones. On each turn, we choose the two heaviest stones and smash them together. Suppose the two heaviest stones have weights x and y with x <= y. The result of this smash is:
x == y, both stones are destroyed.x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.At the end of the game, there is at most one stone left. Return the weight of the last remaining stone. If there are no stones remaining, return 0.
Input: stones = [2, 7, 4, 1, 8, 1]
Output: 1
Explanation: Smash 7 and 8 -> 1 remains. Smash 4 and 2 -> 2 remains.
Smash 1 and 1 -> both destroyed. Smash 2 and 1 -> 1 remains.
Input: stones = [1] Output: 1 Explanation: Only one stone; no smashes occur.
1 <= stones.length <= 301 <= stones[i] <= 1000stones = [2, 7, 4, 1, 8, 1]