C++ Multiset and Priority Queue
Approach 1: Multiset\n\nint lastStoneWeight(vector<int>& st) {\n  multiset<int> s(begin(st), end(st));\n  while (s.size() > 1) {\n    auto w1 = *prev(s.end());\
#### Approach 1: Multiset\n```\nint lastStoneWeight(vector<int>& st) {\n  multiset<int> s(begin(st), end(st));\n  while (s.size() > 1) {\n    auto w1 = *prev(s.end());\n    s.erase(prev(s.end()));\n    auto w2 = *prev(s.end());\n    s.erase(prev(s.end()));\n    if (w1 - w2 > 0) s.insert(w1 - w2);\n  }\n  return s.empty() ? 0 : *s.begin();\n}\n```\n#### Approach 2: Priority Queue\n```\nint lastStoneWeight(vector<int>& st) {\n  priority_queue<int> q(begin(st), end(st));\n  while (q.size() > 1) {\n    auto w1 = q.top(); q.pop();\n    auto w2 = q.top(); q.pop();\n    if (w1 - w2 > 0) q.push(w1 - w2);\n  }\n  return q.empty() ? 0 : q.top();\n}\n```\n#### Complexity Analysys\n- Time: O(n log n) to sort stones.\n- Memory: O(n) for the multiset/queue.
[]