2 pointers O(1) space vs 1 loop||C++ Py3 beats 100%
Intuition1st pass is for applying operations
2nd pass use 2 pointers to reuse the array nums for the answer
Both C++ & Python are made.a 1 loop solution is also
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1st pass is for applying operations
2nd pass use 2 pointers to reuse the array nums for the answer
Both C++ & Python are made.

a 1 loop solution is also made.
# Approach
<!-- Describe your approach to solving the problem. -->
1. Use a loop to proceed the operation to the adjacent pair `(nums[i], nums[i+1])` to get `(nums[i]*2, 0)` for i satisfying `nums[i]==nums[i+1]`
2. 2nd pass uses 2 pointers `i, j` to set `nums[j]=nums[i]; j++` for i with `nums[i]>0`
3. The subarray `nums[j:]` is filled with `0` & return `nums`
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$$O(n)$$
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
Extra: $$O(1)$$ for C++
# Code||C++ Python 0ms 100%
```cpp []
class Solution {
public:
    vector<int> applyOperations(vector<int>& nums) {
        const int n=nums.size();
        for(int i=0; i<n-1; i++){
            if (nums[i]==nums[i+1]){
                nums[i]<<=1;
                nums[i+1]=0;
                i++;// 0 needs no operation
            }
        }
        int j=0;
        for(int i=0; i<n; i++){
            if (nums[i]>0) nums[j++]=nums[i];
        }
        fill(nums.begin()+j, nums.end(), 0);
        return nums;
    }
};
```
```Python []
class Solution:
    def applyOperations(self, nums: List[int]) -> List[int]:
        n, i=len(nums), 0
        while i<n-1:
            if nums[i]==nums[i+1]:
                nums[i], nums[i+1]=nums[i]<<1, 0
                i+=1
            i+=1
        j=0
        for x  in nums:
            if x>0:
                nums[j]=x
                j+=1
        nums[j:]=[0]*(n-j)
        return nums
       
```
# C++ 1 loop ||0ms
```
class Solution {
public:
    vector<int> applyOperations(vector<int>& nums) {
        const int n=nums.size();
        vector<int> ans(n, 0);
        int j=0;
        for(int i=0; i<n-1; i++){
            if (nums[i]==nums[i+1]){
                nums[i]<<=1;
                nums[i+1]=0;
            }
            if (nums[i]) ans[j++]=nums[i];
        }
        if (nums.back()) ans[j++]=nums.back();
        return ans;
    }
};
```
['Two Pointers', 'C++', 'Python3']