Advertisement
nikunjsoni

1046

May 27th, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int lastStoneWeight(vector<int>& A) {
  4.         priority_queue<int> pq(begin(A), end(A));
  5.         while (pq.size() > 1) {
  6.             int x = pq.top(); pq.pop();
  7.             int y = pq.top(); pq.pop();
  8.             if (x > y) pq.push(x - y);
  9.         }
  10.         return pq.empty() ? 0 : pq.top();
  11.     }
  12. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement