Apply Operations to an Array || Beats 100% || Easy Solution in C++
IntuitionThe question clearly states the requirement:
if(nums[i] == nums[i+1]) then doulbe nums[i] and set nums[i+1] as 0.
at the end, we need to move all 0s to
# Intuition
The question clearly states the requirement:
if(nums[i] == nums[i+1]) then doulbe nums[i] and set nums[i+1] as 0.
at the end, we need to move all 0s to the end of the array.

# Approach
<!-- Describe your approach to solving the problem. -->
Step 1: check for consecutive equal elements and apply the operation.
Step 2: count the total number of 0s and delete all 0 entries.
Step 3: push 0s to the end of the array.

# Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    vector<int> applyOperations(vector<int>& nums) {
        int size = nums.size();
        for(int i=0;i<size-1;i++){
            if(nums[i] == nums[i+1]){
                nums[i] *= 2;
                nums[i+1] = 0;
            }
        }
        int count = 0;
        for(int i=0;i<nums.size();i++){
            if(nums[i] == 0){
                count++;
                nums.erase(nums.begin()+i--);
            }
        }
        for(int i=0;i<count;i++){
            nums.push_back(0);
        }
        return nums;
    }
};
 ```
> Consider upvoting if the solution helps!

['C++']