✔️ [C++] SIMULATION 100% ໒( ͡ᵔ ▾ ͡ᵔ )७, Explained
UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.\n\nTo solve this problem, we can conduct an actual simulation o
**UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**\n\nTo solve this problem, we can conduct an actual simulation of the described process. Since we always need to use the heaviest stones, we can use a heap data structure for easy access to max elements.\n\nTime: **O(nlogn)** - for the heap\nSpace: **O(1)** - nothing stored\n\nRuntime: 0 ms, faster than **100.00%** of C++ online submissions for Last Stone Weight.\nMemory Usage: 7.6 MB, less than **34.27%** of C++ online submissions for Last Stone Weight.\n\n```\nclass Solution {\npublic:\n    int lastStoneWeight(vector<int>& s) {\n         make_heap(s.begin(), s.end());\n        \n         while (s.size() > 1) {\n            int x = s.front();\n            pop_heap(s.begin(), s.end());\n            s.pop_back();\n            \n            int y = s.front();\n            pop_heap(s.begin(), s.end());\n            s.pop_back();\n            \n            if (x == y) continue;\n            \n            s.push_back(x - y);\n            push_heap(s.begin(), s.end());\n        }\n        \n        return s.size() ? s.front() : 0;\n    }\n};\n```\n\n**UPVOTE if you like (\uD83C\uDF38\u25E0\u203F\u25E0), If you have any question, feel free to ask.**
['C']