Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f40fa85

Browse files
[CREATE] [CPP] 1046. Last Stone Weight
1 parent 4884c73 commit f40fa85

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cpp/1046-Last-Stone-Weight.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int lastStoneWeight(vector<int>& stones) {
4+
priority_queue<int, vector<int>> pq(stones.begin(), stones.end());
5+
pq.push(0);
6+
7+
while (pq.size()>=1) {
8+
int t1 = pq.top();
9+
pq.pop();
10+
if(pq.empty()) break;
11+
int t2 = pq.top();
12+
pq.pop();
13+
pq.push(abs(t1-t2));
14+
}
15+
16+
return pq.top();
17+
}
18+
};

0 commit comments

Comments
 (0)