✅Java Easy Solution|lBeginner Friendly🔥
Code\n\nclass Solution {\n    public int lastStoneWeight(int[] stones) {\n        //creating a heap to store elements in descending order\n        PriorityQueue
# Code\n```\nclass Solution {\n    public int lastStoneWeight(int[] stones) {\n        //creating a heap to store elements in descending order\n        PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.reverseOrder());\n        for(int i = 0 ; i < stones.length; i ++){\n            q.add(stones[i]);\n        }\n        while(q.size() > 1){\n            int x = q.poll();\n            int y = q.poll();\n            if(x == y){\n                continue;\n            }else{\n                q.add(Math.abs(y - x));\n            }\n        }\n        if(q.size() == 1){\n            return q.poll();\n        }\n        return 0;\n    }\n}\n```\n**Please UpVote If you like it Happy Coding :)\nIf you really found my solution helpful please upvote it, as it motivates me to post such kind of codes and help the coding community, if you have some queries or some improvements please feel free to comment and share your views.**
['Heap (Priority Queue)', 'Java']