| 14 | class Solution { |
| 15 | public: |
| 16 | int lastStoneWeight(vector<int>& stones) { |
| 17 | priority_queue<int> pq (stones.begin(), stones.end()); |
| 18 | while (pq.size() >= 2) { |
| 19 | int x = pq.top(); pq.pop(); |
| 20 | int y = pq.top(); pq.pop(); |
| 21 | if (x > y) { |
| 22 | pq.push(x - y); |
| 23 | } |
| 24 | } |
| 25 | return pq.size() == 0 ? 0 : pq.top(); |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 |