
class Solution {
public int connectSticks(int[] sticks) {
PriorityQueue<Integer> heap = new PriorityQueue<>();
int cost = 0;
for(int n : sticks) {
heap.add(n);
}
while(heap.size() > 1) {
int x = heap.poll();
int y = heap.poll();
cost += x+y;
heap.add(x+y);
}
return cost;
}
}