1046. Last Stone Weight
Practice Last Stone Weight for free on NudgeCode: Easy, Heap pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
You have a pile of stones with the given weights. Repeatedly take the two heaviest stones x <= y and smash them together: if x == y both are destroyed, otherwise x is destroyed and y becomes y - x.
When at most one stone is left, return its weight, or 0 if none are left.
Example
stones = [2,7,4,1,8,1] -> 1
Constraints
- 1 <= stones.length <= 30
- 1 <= stones[i] <= 1000