✅ Java best intuitive solution || Priority Queue || 1ms 99% faster
Code\njava\npublic int lastStoneWeight(int[] stones) {\n\tPriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());\n\tfor(int st: stones)\n\
**Code**\n```java\npublic int lastStoneWeight(int[] stones) {\n\tPriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());\n\tfor(int st: stones)\n\t\tpq.offer(st);\n\n\twhile(pq.size() > 1) {\n\t\tint f = pq.poll();\n\t\tint s = pq.poll();\n\t\tif(f != s) \n\t\t\tpq.offer(f-s);\n\t}\n\n\treturn pq.isEmpty() ? 0 : pq.peek();\n}\n```\n\n**Explanation**\nWe were required to do operations each time on largest elements, and for that we can use max heap which can use used by reverting the order of priority queue available in Collections framework in java.\n- Push all elements in priority queue.\n- Iterate while the size of priority queue becomes equal to or less than 1.\n- Pop two largest element from top and perform following checks\n\t- if both are equal then we don\'t need to do anything.\n\t- else we add the difference of `f` and `s` to the priority queue.\n- Now return 0 if size of `pq` is 0 otherwise return top element.\n\nHere\'s how it works:-\n\n![image](https://assets.leetcode.com/users/images/89bb3992-f3ba-410e-a071-62c44831876a_1649307957.4194489.png)\n\n\nHope it helps,\nIf it does do upvote\nThanks
['Heap (Priority Queue)', 'Java']