LeetCode Solutions/Problems/2460. Apply Operations to an Array.java
class Solution {
    void swap(int[] nums, int i, int j){
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
    public int[] applyOperations(int[] nums) {
        for (int i=0, j=0; i<nums.length; ++i){
            if (i+1 < nums.length && nums[i] == nums[i+1]){
                nums[i] *= 2;
                nums[i + 1] = 0;
            }
            if (nums[i] != 0){
                swap(nums, i, j);
                j++;
            }
        }
        return nums;
    }
}