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

Method lastStoneWeight

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

topMethod · 0.45
popMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected