Given a multiset of stone weights, repeatedly smash the two heaviest stones together. If the stones have equal weight, both are destroyed; otherwise the difference remains. Return the weight of the last remaining stone, or 0 if none remain.
stones = array of stone weights
weight of the final stone, or 0
Example 1:
Input:
stones = [2,7,4,1,8,1]
Output:
1
Explanation:
Repeated smashing leaves a final stone of weight 1.
Example 2:
Input:
stones = [1]
Output:
1
Explanation:
Only one stone exists, so it remains unchanged.