Skip to content

Commit

Permalink
Added Last Stone Weight Problem Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
jyoti-bhasin committed Oct 30, 2022
1 parent ab4b7bd commit df3dac3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions leetcode/Last_Stone_Weight.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public:
int lastStoneWeight(vector<int>& s)
{
priority_queue<int> q(s.begin(),s.end());
while(q.size()>1)
{
int a=q.top();
q.pop();
int b=q.top();
q.pop();
if(a!=b)
q.push(a-b);

}

if(q.empty())
return 0;
return q.top();
}
};

0 comments on commit df3dac3

Please sign in to comment.