leetCode1046

mac2024-11-11  11

class Solution { public: int lastStoneWeight(vector<int>& stones) { int x,y; while(1) { if(stones.size() <=1) { break; } sort(stones.begin(),stones.end()); x = stones[stones.size()-1]; y = stones[stones.size()-2]; stones.erase(stones.begin()+ (int)stones.size()-2,stones.end()); if(x!=y) { stones.push_back(x-y); } } return stones.size() == 0 ? 0 : stones[0]; } };

 

最新回复(0)