当前位置: 代码迷 >> 综合 >> leetcode 1046. Last Stone Weight (easy)
  详细解决方案

leetcode 1046. Last Stone Weight (easy)

热度:81   发布时间:2024-01-05 00:22:06.0

水,算是复习了下vector的应用吧…

class Solution
{
    
public:int lastStoneWeight(vector<int> &stones){
    int size = stones.size();if (size == 1){
    return stones[0];}sort(stones.begin(), stones.end());while (size >= 2){
    stones[size - 2] = stones[size - 1] - stones[size - 2];stones.resize(size - 1);sort(stones.begin(), stones.end());size--;}return stones.size() == 0 ? 0 : stones[0];}
};
  相关解决方案