public class Solution {
public int LastStoneWeight(int[] stones) {
var pq = new PriorityQueue<int, int>(
stones.Select(x => (x, x)),
Comparer<int>.Create((a, b) => b.CompareTo(a)));
while (pq.Count > 1) {
int x = pq.Dequeue();
int y = pq.Dequeue();
if (x > y)
pq.Enqueue(x - y, x - y);
}
return pq.Count == 0 ? 0 : pq.Peek();
}
}Insert it in a max heap. Keep taking out two stones and do the logic.