👏Beats 93.57% of users with Java || 1ms Easy & Simple Explained Solution 🔥💥
Intuition\nCheck over the array if ith index and i+1th index are same then ith index element multiply by 2 and make i+1th inddex as a 0.\n\n# I Think This Can H
# Intuition\nCheck over the array if ith index and i+1th index are same then ith index element multiply by 2 and make i+1th inddex as a 0.\n\n# I Think This Can Help You\n![Screenshot 2024-02-24 232407.png](https://assets.leetcode.com/users/images/db05d5a6-844a-457f-9726-0adb5319b6d3_1710230123.5292735.png)\n\n\n# Approach\n1. Iterate over the nums and check if ith index element and i+1th index element both are same then ith index elemen multiply by 2 & i+1th index element is equal to 0.\n2. Create ans array variable to store answer array(We use extra array for reduce time complexity).\n3. Make cnt variable for maintain ans array index.\n4. Itearate over the loop and add element of cnt in the ans it is not equal to 0.\n5. return ans array.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)  --> for extra array ans\n\n# Code\n```\nclass Solution {\n    public int[] applyOperations(int[] nums) {\n        for(int i=0;i<nums.length-1;i++){   // Iterate over the nums and check if ith index element and i+1th index element both are same then ith index elemen multiply by 2 & i+1th index element is equal to 0.\n            if(nums[i]==nums[i+1]){\n                nums[i] = nums[i] * 2;\n                nums[i+1] = 0;\n            }\n        }\n        int[] ans = new int[nums.length];   // Create ans array variable to store answer array(We use extra array for reduce time complexity).\n        int cnt=0;   // Make cnt variable for maintain ans array index.\n        for(int i=0;i<nums.length;i++){   // Itearate over the loop and add element of cnt in the ans it is not equal to 0.\n            if(nums[i]!=0){\n                ans[cnt] = nums[i];\n                cnt++;\n            }\n        }\n        return ans;   // return ans array.\n    }\n}\n```\n\n![_5aa88f78-fb67-453e-9e02-bc042a0631cd.jpeg](https://assets.leetcode.com/users/images/9d684b2b-0116-42e3-aa3e-cf91560707ba_1710230191.6701322.jpeg)\n
['Array', 'Simulation', 'Java']