Skip to content

Commit be5eceb

Browse files
authored
Create 1046.LastStoneWeight.cpp
1 parent f7da6d9 commit be5eceb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)