2 Approaches- choose yourself🤔🤔|| cpp solution
Intuition\n Describe your first thoughts on how to solve this problem. \nHere we have to do, if nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHere we have to do, if nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. Otherwise, you skip this operation. and then move zeroes to end. If you havent solved **move zeroes**(leetcode- 283) problem, u can solve that also after solving this question. \n\n# Approach No. 1(beats 39%) \n# SPACE OPTIMIZED \n<!-- Describe your approach to solving the problem. -->\n1. Iterate through the array and do the following,\n- If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0.\n- Otherwise, you skip this operation.\n2. Iterate again throughout the array and shift all zeroes to end and non- zero in ascending order.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(2N) equivalent to O(N)\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> applyOperations(vector<int>& nums) {\n        for(int i = 0; i < nums.size()-1; i++){\n            if(nums[i] == nums[i+1])\n            {\n                nums[i] *= 2;\n                nums[i+1] = 0;\n                i++; \n            }\n        }\n        int temp = 0;\n        for(int i = 0; i < nums.size(); i++){\n            if((i == temp) && nums[i] != 0){\n                temp++;\n                continue;\n            }\n            if(nums[i] != 0){\n                nums[temp] = nums[i];\n                temp++;\n                nums[i] = 0;\n            }\n        }\n        return nums;\n    }\n};\n```\n# Approach No. 2(beats 90%)\n# TIME OPTIMIZED\n1. Iterate through the array and do the following,\n- If nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] to 0. \n- check if nums[i] == 0 or not,\n- nums[i] == 0, store in v1, else v2.\n- for the last index, do it seperately.\n2. erase  nums, and set nums to v2. and then insert v1.\n\n# COMPLEXITY \n- **TIME** - O(N)\n- **SPACE**- O(2N) equivalent to O(N)\n\n# CODE\n```\nclass Solution {\npublic:\n    vector<int> applyOperations(vector<int>& nums) {\n        vector<int> v1; // zero vector\n        vector<int> v2; // non-zero vector\n        for(int i = 0; i < nums.size()-1; i++){\n            if(nums[i] == nums[i+1])\n            {\n                nums[i] *= 2;\n                nums[i+1] = 0;\n            }\n             if(nums[i]==0)\n                v1.push_back(nums[i]);\n            else\n                v2.push_back(nums[i]);\n        }\n        // for last element \n        if(nums[nums.size()-1]==0)\n            v1.push_back(nums[nums.size()-1]);\n        else\n            v2.push_back(nums[nums.size()-1]);\n        nums.erase(nums.begin(), nums.end());\n        // sort(v2.begin(), v2.end());\n        nums = v2;\n        for(auto i : v1)\n        nums.push_back(i);\n        return nums;\n    }\n};\n```
['Array', 'Simulation', 'C++']