1046.Last Stone Weight
class Solution {
public:
int lastStoneWeight(vector<int>& stones) {
if(stones.size()==1) return stones[0];
priority_queue<int> tmp(stones.begin(),stones.end());
while(tmp.size()>1)
{
int max=tmp.top();
tmp.pop();
int sec=tmp.top();
tmp.pop();
int res=max-sec;
tmp.push(res);
}
return tmp.top();
}
};Last updated