✔️ 2ms C++ solution | Explained
Here is the solution along with explanations in the comments:\n\nC++ []\nclass Solution {\npublic:\n    vector<int> applyOperations(vector<int>& nums) {\n      
Here is the solution along with explanations in the comments:\n\n``` C++ []\nclass Solution {\npublic:\n    vector<int> applyOperations(vector<int>& nums) {\n        for (int i{0}; i<nums.size()-1; ++i) {\n            // checking if the number matches with the next one or not\n            if (nums[i]==nums[i+1]) {\n                // set the first number of the matching pair to twice it\'s value & other to 0\n                nums[i]*=2;\n                nums[i+1]=0;\n                // i++ because the next element is already set to 0 and can\'t be same as it\'s next one\n                // so we need to skip it\n                i++;\n            }\n        }\n        \n        // this function moves 0 to last\n        for (int i{1},j{0}; i<nums.size(); ++i) {\n            // if element at j is -ve, then we check if element at index i is something\n            // other than 0 or not. If it is then we swap otherwise,\n            // we don\'t increment j and move i to the next index and try to swap\n            if (!nums[j]) {\n                if (nums[i]) swap(nums[i], nums[j++]);\n            } else j++;\n        }\n        \n        return nums;        \n    }\n};\n```\n\n*Upvote if the solution helped you!*
['C++']