We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8c3b1eb commit 917f145Copy full SHA for 917f145
last_stone_weight.cpp
@@ -0,0 +1,18 @@
1
+class Solution {
2
+public:
3
+ int lastStoneWeight(vector<int>& stones) {
4
+ priority_queue<int> Q;
5
+ for(auto stone : stones) {
6
+ Q.emplace(stone);
7
+ }
8
+
9
+ while(!Q.empty()) {
10
+ if(Q.size() == 1) return Q.top();
11
+ int x = Q.top(); Q.pop();
12
+ int y = Q.top(); Q.pop();
13
+ if(x != y)
14
+ Q.push(x - y);
15
16
+ return 0;
17
18
+};
0 commit comments