MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / Solution

Class Solution

1046. Last Stone Weight/Solution.cpp:14–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12using namespace std;
13
14class Solution {
15public:
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
30int main() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected