Skip to content

Commit 1e616fa

Browse files
committed
working commit - Created using LeetHub
1 parent ca75d25 commit 1e616fa

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
   int lastStoneWeight(vector<int>& stones) {
4+
       priority_queue<int> pq;
5+
       for(auto x: stones)
6+
           pq.push(x);
7+
       
8+
       while(pq.size() > 1){
9+
           int a = pq.top();pq.pop();
10+
           int b = pq.top();pq.pop();
11+
           
12+
           if(a != b)
13+
               pq.push(a - b);                
14+
      }
15+
       
16+
       if(!pq.empty())
17+
           return pq.top();
18+
       else
19+
           return 0;
20+
  }
21+
};

0 commit comments

Comments
 (0)