Simple solution | Runtime 0 ms | Beats 100.00%
IntuitionPerform the operation as given, ensuring merged values are stored while skipping zeros. After processing, append the remaining zeros to maintain array
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Perform the operation as given, ensuring merged values are stored while skipping zeros. After processing, append the remaining zeros to maintain array size.

# Approach
<!-- Describe your approach to solving the problem. -->

1. **Initialization**: Initialize `i` with 0. Use a `while` loop to traverse the array from left to right.  

2. **Skip Zeros**: If `nums[i-1] == 0`, simply move to the next element without adding it to `ans`.

3.  **Merge Adjacent Equal Elements**: If `nums[i] == nums[i-1]`, double `nums[i-1]`, set `nums[i]` to `0`, and store the doubled value in the result vector `ans`.  

4. **Store Non-Zero Elements**: If the numbers are not equal, push `nums[i-1]` into `ans`.  

5. **Add the Last Element**: Ensure the last element of `nums` is included in `ans`.  

6. **Fill Remaining Spaces with Zeroes**: If `ans` is smaller than `nums`, append zeros to match the original size.

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

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

# Code
```cpp []
class Solution {
public:
    vector<int> applyOperations(vector<int>& nums) {
        vector<int> ans;
        int i=1;
        while( i<nums.size()) {
            if(nums[i-1] == 0){
                // skip it
                i++;
            }
            else if(nums[i] == nums[i-1]) {
                nums[i-1] *= 2;
                nums[i] = 0;
                ans.push_back(nums[i-1]);
                i+=2;
            }
            else {
                ans.push_back(nums[i-1]);
                i++;
            }
        }

        ans.push_back(nums[nums.size()-1]); // insert the last element

        // fill rest of the array with zeroes
        for(i=ans.size(); i<nums.size(); i++) {
            ans.push_back(0);
        }

        return ans;
    }
};
```
['C++']