JAVA | Constant space | Easy ✅
Please Upvote :D\n\nclass Solution {\n    public int[] applyOperations(int[] nums) {\n        int n = nums.length;\n        \n        for (int i = 0; i < n - 1;
### **Please Upvote** :D\n```\nclass Solution {\n    public int[] applyOperations(int[] nums) {\n        int n = nums.length;\n        \n        for (int i = 0; i < n - 1; i++) {\n            if (nums[i] == nums[i + 1]) {\n                nums[i] *= 2;\n                nums[i + 1] = 0;\n            }\n        }\n        \n        int i = 0, j = 0;\n        \n        while (j < n) {\n            if (nums[j] != 0) {\n                nums[i++] = nums[j];\n            }\n            j++;\n        }\n        \n        while (i < n) {\n            nums[i++] = 0;\n        }\n        \n        return nums;\n    }\n}\n\n// TC: O(n), SC: O(1)\n```
['Java']