水,算是复习了下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];}
};