Skip to content

Latest commit

 

History

History
17 lines (12 loc) · 403 Bytes

1046. 最后一块石头的重量.md

File metadata and controls

17 lines (12 loc) · 403 Bytes
  • 排序
function lastStoneWeight(stones: number[]): number {

    while (stones.length > 1) {
        stones.sort((a, b) => b - a); // 使用堆排序更佳
        const offset: number = stones.shift() - stones.shift();
        offset && stones.push(offset);
    }

    return stones[0] || 0;
};