Skip to content

Commit e9e43d4

Browse files
authored
Merge pull request #1 from priyansh13-c/priyansh13-c-patch-1
Create lastStoneWeight.java
2 parents 44cae86 + 7fd3473 commit e9e43d4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lastStoneWeight.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int lastStoneWeight(int[] stones) {
3+
PriorityQueue<Integer> pq= new PriorityQueue<>(Collections.reverseOrder());
4+
5+
for(int val:stones) pq.add(val);
6+
7+
while(pq.size()>1){
8+
int y = pq.remove();
9+
int x = pq.remove();
10+
11+
if(x!=y) pq.add(y-x);
12+
}
13+
return pq.size()>0? pq.remove() : 0;
14+
}
15+
}

0 commit comments

Comments
 (0)