JAVA | apply-operations-to-an-array
\nclass Solution {\n    public int[] applyOperations(int[] nums) {\n        int k=0;\n        int n=nums.length;\n        for(int i=0;i<n-1;i++)\n        {\n   
```\nclass Solution {\n    public int[] applyOperations(int[] nums) {\n        int k=0;\n        int n=nums.length;\n        for(int i=0;i<n-1;i++)\n        {\n            if(nums[i]==nums[i+1]){\n                nums[i]*=2;\n                nums[i+1]=0;\n            }\n            if(nums[i]!=0)nums[k++]=nums[i];\n        }\n        if(nums[n-1]!=0)nums[k++]=nums[n-1];\n        \n        for(int j=k;j<n;j++)nums[j]=0;\n        \n        return nums;\n    }\n}\n```
['Java']