Skip to content

Latest commit

 

History

History
70 lines (48 loc) · 1.42 KB

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

File metadata and controls

70 lines (48 loc) · 1.42 KB
title tags categories author comments updated permalink mathjax top description date
[1046] 最后一块石头的重量
leetcode
leetcode
张学志
true
false
false
false
...
2019-12-31 16:17:26 -0800

题目描述

有一堆石头,每块石头的重量都是正整数。

每一回合,从中选出两块最重的石头,然后将它们一起粉碎。假设石头的重量分别为 x 和 y,且 x <= y。那么粉碎的可能结果如下:

  • 如果 x == y,那么两块石头都会被完全粉碎;
  • 如果 x != y,那么重量为 x 的石头将会完全粉碎,而重量为 y 的石头新重量为 y-x

最后,最多只会剩下一块石头。返回此石头的重量。如果没有石头剩下,就返回 0

 

提示:

  1. 1 <= stones.length <= 30
  2. 1 <= stones[i] <= 1000
Related Topics
  • 贪心算法
  • 题目代码

    class Solution {
    public:
        int lastStoneWeight(vector<int>& stones) {
    
        }
    };

    题目解析

    方法一

    方法二

    方法三