Easy Solution Using Java with Explaination
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nThe approach is to use 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe approach is to use an arraylist and then add the elements in it.\nif nums[i]==nums[i+1] then we multiply  nums[i]*=2 & set nums[i+1]=0.\nThen we count the number of zeros in the array. And move it to the end of the array by using arraylists.\nThen we return the nums array which has been updated with new values.\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] applyOperations(int[] nums) {\n        int n = nums.length;\n        ArrayList<Integer> list = new ArrayList<>();\n        for(int i=0; i<n; i++){\n            if(i<n-1){\n                if(nums[i]==nums[i+1]){\n                    nums[i]*=2;\n                    nums[i+1]=0;\n                }\n            }\n        }\n        int count=0;\n        for(int i=0;i<n;i++){\n            if(nums[i]==0){\n                count++;\n            }\n        }\n        for(int i=0; i<n;i++){\n            if(nums[i]!=0){\n                list.add(nums[i]);\n            }\n        }\n        for(int i=0; i<count; i++){\n            list.add(0);\n        }\n       for (int i = 0; i < list.size(); i++){\n            nums[i] = list.get(i);\n    }\n        return nums;\n    }\n}\n```\n### If you like the solution then please upvote me.\n\n\n## Thanks to @arun2020 he gave the solution in O(1) space.\n\n### His Approach is as follow\nThe approach is to first check if the adjacent elements are equal. If they are, then we multiply them and make the next element zero. After this, we shift all zeroes to right side of array using two pointers technique.\n\n# Code\n```\nclass Solution {\n    public int[] applyOperations(int[] a) {\n        int n = a.length;\n    for (int i = 0; i < n - 1; i++) {\n       if (a[i] == a[i + 1]) {\n            a[i] = 2 * a[i];\n            a[i + 1] = 0;\n        }\n    }\n    int high=0;\n    int low=0;\n    while(high<n && low<n){\n    if(a[high]!=0 && a[low]!=0){\n    high++;\n    low++;\n}\n    else if(a[low]==0 && a[high]==0){\n    high++;\n}\n    else{\n        int temp = a[low];\n        a[low] = a[high];\n        a[high] = temp;\n        low++;\n        high++;\n}\n}\nreturn a;\n}\n    }\n\n```\n\n## Thanks @here-comes-the-g for beautiful approach\n### His Approach is as follows:\nFor each pair of numbers, if they are equal, double the first number and set the second to zero.\nMove all zeros to the end of the array by moving non-zero numbers one at a time from left to right until there are no more non-zeros on the left side of any zeros in between them.\n\n# Code\n```\nclass Solution {\n    public int[] applyOperations(int[] nums) {\n        int n = nums.length;\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        for(int i=0, left =0; i<n;i++){\n            if(nums[i]!=0){\n            int temp = nums[i];\n            nums[i] = 0;\n            nums[left]=temp;\n            left++;\n            }\n        }\n        return nums;\n    }\n}\n```\n\n\n
['Java']