dsa · easy

Last Stone Weight

GreyOrangeHeapGreedyFoundation

Each turn smash the two heaviest stones. If equal, both gone; else the difference goes back. Return the last stone weight (or 0).

Arguments

**Example:** [2,7,4,1,8,1]1.

Constraints

1 <= stones.length <= 30, 1 <= stones[i] <= 1000 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
[2,7,4,1,8,1]

Expected:
1

Example 2

Input:
[1]

Expected:
1

Open in the Dojo editor