1、
2、//自己写的解法
class Solution {
public:
int lastStoneWeight(vector<int>& stones) {
int temp0=0;
int temp1=0;
int temp=0;
while(stones.size()>1)
{
sort(stones.begin(),stones.end());
temp0=stones.back();
stones.pop_back();
temp1=stones.back();
stones.pop_back() ;
temp=temp0-temp1;
if(temp!=0)
{
stones.push_back(temp);
}
}
if(stones.empty())
{
return 0;
}else{
return stones[0];
}
}
};
3、贪心