Last Stone Weight
Easy
Topics
You are given stones weights. Each turn, smash the two heaviest together: if equal both are destroyed, else the lighter is destroyed and the heavier becomes their difference. Return the weight of the last remaining stone, or 0 if none remain.
Example 1
Input: stones = [2,7,4,1,8,1] Output: 1
Example 2
Input: stones = [1] Output: 1
Constraints
- 1 <= stones.length <= 30
- 1 <= stones[i] <= 1000
Run ⌘' · Submit ⌘⏎