Optimal Solution ✅  for Applying Operations and Shifting Zeros in an Array
BEATS 100% 🚀Intuition 💡When two consecutive numbers are the same, we double the first and set the next to zero. Then, we simply move all non-zero numbers to the
### BEATS 100% 🚀
![image.png](https://assets.leetcode.com/users/images/9ccceed2-4766-43be-89d4-ccbe4ec29c27_1740834134.8252292.png)


# Intuition 💡
When two consecutive numbers are the same, we double the first and set the next to zero. Then, we simply move all non-zero numbers to the front and push zeros to the end.

# Approach 🔍
1. Go through the array and double any number that equals the next one.
2. Move all non-zero numbers to the front of the array.
3. Fill the remaining places with zeros.

# Complexity ⏱️
- **Time complexity:** $$O(n)$$ (we loop through the array twice).
- **Space complexity:** $$O(1)$$ (in-place modification).

# Code
```cpp []
class Solution {
public:
    vector<int> applyOperations(vector<int>& nums) {
        for (int i = 0; i < nums.size() - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                nums[i] = 2 * nums[i];
                nums[i + 1] = 0;
            }
        }
        int pos = 0;
        for (int i = 0; i < nums.size(); i++) {
            if (nums[i] != 0) {
                nums[pos] = nums[i];
                pos++;
            }
        }
        while (pos < nums.size()) {
            nums[pos] = 0;
            pos++;
        }
        return nums;
    }
};
```
['Two Pointers', 'C++']