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.
2 parents 905657b + bc1b8dc commit 4d35a92Copy full SHA for 4d35a92
Leetcode2023/April2023/C++/1046.LastStoneWeight.cpp
@@ -0,0 +1,17 @@
1
+class Solution {
2
+public:
3
+ int lastStoneWeight(vector<int>& stones) {
4
+
5
+ int n = stones.size();
6
+ priority_queue<int>pq(stones.begin(),stones.end());
7
8
+ while(pq.size()>1)
9
+ {
10
+ int a = pq.top(); pq.pop();
11
+ int b = pq.top(); pq.pop();
12
+ int c = a-b;
13
+ pq.push(c);
14
+ }
15
+ return pq.top();
16
17
+};
0 commit comments