contains category wise problems(data structures, competitive) of popular platforms.
View the Project on GitHub mayankdutta/category-wise-problems
priority queue
.class Solution {
public int lastStoneWeight(int[] stones) {
PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<>() {
@Override
public int compare(Integer one, Integer two) {
return two.compareTo(one);
}
});
for (Integer i: stones) pq.add(i);
while (pq.size() > 1) {
int one = pq.poll();
int two = pq.poll();
pq.add(Math.abs(one - two));
}
if (pq.isEmpty()) return 0;
return pq.peek();
}
}