JAVA CODE
Complexity
Time complexity:  O(n)

Space complexity:  O(1)
Code


# 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
```java []
class Solution {
    public int[] applyOperations(int[] nums) {
        int n = nums.length;

        //Simulation
        int j = 0;
        for(int i = 0; i < n; i++) {
            if(i+1 < n && nums[i] == nums[i+1] && nums[i] != 0) {
                nums[i] *= 2;
                nums[i+1] = 0;
            }

            if(nums[i] != 0) {
                if(i != j) {
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
                j++;
            }
        }

        return nums;
    }
}
```
['Java']