package leetcode;

/**
 * https://leetcode.com/problems/last-stone-weight/
 */
public class Problem1046 {
    public int lastStoneWeight(int[] stones) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1046 prob = new Problem1046();
        System.out.println(prob.lastStoneWeight(new int[]{2, 7, 4, 1, 8, 1})); // 1
    }
}

@@ -12,16 +12,78 @@
 tcode;%0A%0A
+import java.util.Comparator;%0Aimport java.util.PriorityQueue;%0A%0A
 /**%0A * h
@@ -220,215 +220,506 @@
     
-// TODO%0A        return 0;%0A
+PriorityQueue%3CInteger%3E queue = new PriorityQueue%3C%3E(Comparator.reverseOrder());%0A        for (int stone : stones) %7B%0A            queue.add(stone);%0A    
     %7D%0A
-%0A
+   
     
-public static void main(String%5B%5D args) %7B%0A        Problem1046 prob = new Problem1046();%0A        System.out.println(prob.lastStoneWeight(new int%5B%5D%7B2, 7, 4, 1, 8, 1%7D)); // 1
+ while (!queue.isEmpty()) %7B%0A            Integer x = queue.poll();%0A            if (queue.isEmpty()) %7B%0A                return x;%0A            %7D%0A            Integer y = queue.poll();%0A            int diff = Math.max(x, y) - Math.min(x, y);%0A            if (diff %3E 0) %7B%0A                queue.add(diff);%0A            %7D%0A        %7D%0A        return 0;
 %0A   

Solve problem 1046