simplest c++ solution with comments
\nclass Solution {\npublic:\n    int lastStoneWeight(vector<int>& stones) {\n        priority_queue<int> pq;  //create max heap having maximum element at top\n 
```\nclass Solution {\npublic:\n    int lastStoneWeight(vector<int>& stones) {\n        priority_queue<int> pq;  //create max heap having maximum element at top\n        for(int x:stones)               //insert all elements into priority queue \n            pq.push(x);\n        while(pq.size()>1){        //iterate until size is equal to 1\n            int fval=pq.top();      //fval is first max val\n            pq.pop();\n            int sval=pq.top();     //sval is second max val\n            pq.pop();\n            if(fval==sval){          //if both equal simply push 0 since both stones destroyed\n                pq.push(0);\n            }\n            else if(fval>sval){         //if both not equal substract small val to larger  one and insert \n                pq.push(fval-sval);\n            }\n        }\n        return pq.top();       //finally return top value\n    }\n};\n```\nTC : O(nlogn)     \nSC : O(N)\nIf you like the solution please upvote. :)
['Heap (Priority Queue)']