[Java][Two-Pointer] Beat 100%
IntuitionThe problem requires merging adjacent equal elements and shifting non-zero values to the front while maintaining their order. A simple traversal can ac
# Intuition
The problem requires merging adjacent equal elements and shifting non-zero values to the front while maintaining their order. A simple traversal can achieve this efficiently.

# Approach
- Iterate through the array and merge consecutive equal elements by doubling the first one and skipping the second.
- Store non-zero elements sequentially in a new array.
- Return the modified array with remaining positions filled with zeros.

# Complexity
- **Time complexity:** \( O(n) \) — Single pass through the array.
- **Space complexity:** \( O(n) \) — Uses an extra array for results.

# Code
```java []
class Solution {
    public int[] applyOperations(int[] nums) {

        int[] res = new int[nums.length];
        int j = 0;

        for (int i = 0 ; i < nums.length ; i++) {
            if(nums[i] == 0){
            } else if( i + 1  < nums.length && nums[i] == nums[i+1]) {
                res[j++] = nums[i] * 2;
                i += 1;
            }else {
                res[j++] = nums[i];
            }
        }
        return res;
    }
}

['Java']