Java One-pass | Time O(n) | Space O(n)
\nclass Solution {\n    public int[] applyOperations(int[] nums) {\n        int[] ans = new int[nums.length];\n        if (nums.length == 0) return ans;\n      
```\nclass Solution {\n    public int[] applyOperations(int[] nums) {\n        int[] ans = new int[nums.length];\n        if (nums.length == 0) return ans;\n        int pointer = 0;\n        for (int i = 0; i < nums.length - 1; i++) {\n            if (nums[i] == nums[i + 1] && nums[i] != 0) {\n                nums[i] *= 2;\n                ans[pointer++] = nums[i];\n                nums[i + 1] = 0;\n            } else if (nums[i] != 0) {\n                ans[pointer++] = nums[i];\n            }\n        }\n        if (nums[nums.length - 1] != 0) {\n            ans[pointer] = nums[nums.length - 1];\n        }\n        return ans;\n    }\n}\n```
['Java']