[Java] Runtime: 1ms, faster than 99.49% || Queue and Iterative Solutions
PriorityQueue solution:\n\nclass Solution {\n    public int lastStoneWeight(int[] stones) {\n        Queue<Integer> queue = new PriorityQueue<>(Collections.reve
PriorityQueue solution:\n```\nclass Solution {\n    public int lastStoneWeight(int[] stones) {\n        Queue<Integer> queue = new PriorityQueue<>(Collections.reverseOrder());\n        for (int i : stones) queue.offer(i);\n\n        while (queue.size() > 1) {\n            int first = queue.poll();\n            int next = queue.poll();\n            if (first != next) {\n                queue.offer(first - next);\n            }\n        }\n        return queue.isEmpty() ? 0 : queue.poll();\n    }\n}\n```\n\nWithout extra space solution:\n```\nclass Solution {\n    public int lastStoneWeight(int[] stones) {\n        if (stones.length == 1) return stones[0];\n        Arrays.sort(stones);\n        int last = stones.length - 1;\n        int prev = stones.length - 2;\n        while (stones[last] != 0) {\n            if (stones[prev] == 0) return stones[last];\n            stones[last] = stones[last] - stones[prev];\n            stones[prev] = 0;\n            Arrays.sort(stones);\n        }\n        return 0;\n    }\n}\n```\n\n![image](https://assets.leetcode.com/users/images/c808e6a5-e57b-427e-98eb-31b4ffa029bb_1668743243.4978485.png)\n
['Java']