✅ 🔥 0ms Runtime Beats 100% ||  Efficient Array Transformation: Merging & Zero Shifting 🚀
🌟 Intuition:The task is to modify the array by merging adjacent equal elements and moving zeros to the end. The idea is to:Merge Adjacent Equal Elements: If two
![Capture3.PNG](https://assets.leetcode.com/users/images/9bbb639a-0c33-43f7-8968-41a20e8cf9cf_1741006894.2690184.png)
# 🌟 Intuition:
The task is to modify the array by merging adjacent equal elements and moving zeros to the end. ***The idea is to:***

**Merge Adjacent Equal Elements:** If two adjacent numbers are the same, combine them into one, doubling its value.

**Move Zeros to the End:** All zeros should be shifted to the end, keeping the order of the non-zero elements.

**Key Observations:**
We can process each element just once to achieve the desired result.
We’ll need to skip zeros while iterating and place the merged elements in the correct position.

# 🧠 Approach:
**Let’s break it down in simple steps:**

**Traverse the Array:** Loop through the array. If two adjacent numbers are equal, merge them (double the value) and skip the next one.

**Skip Zeros:** If a number is zero, we don’t need to do anything with it—just move to the next element.

**Temporary Array:** Use a temporary array to store the modified values.

**Return the Result:** After processing all elements, return the modified array.

# ⏱ Complexity
- **Time complexity:**
*****O(n)*****, where n is the length of the array. We go through the array once, making it efficient.

- **Space complexity:**
***O(n)***, because we use an additional array (temp) to store the results.

# 🔍 Explanation of the Code 
- ***Array Traversal:*** Loop through nums, merging equal elements and copying non-zero elements to temp.
- ***Skip Zeros:*** Zeros are ignored in the result.
- ***Edge Case:*** The last element is processed differently since it doesn’t have a next element to compare to.

# 🎯 Example Walkthrough
 **Example 1:**
Input: nums = [1, 2, 2, 4, 0]

- **Steps:**
Compare nums[0] = 1 with nums[1] = 2: They’re not equal, so copy 1.
Compare nums[1] = 2 with nums[2] = 2: They are equal, so double it to 4 and skip the next element.
Compare nums[3] = 4 with nums[4] = 0: Copy 4 and skip zero.
**Final Output: [1, 4, 4, 0, 0]** 🎉
# 🚀 Conclusion
We keep things simple and use an extra array to store the result. The approach is perfect for large arrays, and it’s easy to implement.

**Good luck with your LeetCode challenge! ✨**
# Code
```java []
class Solution {
    public int[] applyOperations(int[] nums) {
        int[] temp =new int[nums.length];
        int k=0;
        for(int i=0;i<nums.length;i++){
             if(i==nums.length-1){
               temp[k]=nums[i] ;
               break;
            }
            if(nums[i]!=0){
         if(nums[i]==nums[i+1]){
        temp[k]=nums[i]*2;
        i=i+1;
         }
         
         else {
         temp[k]=nums[i];
         }
         
         k++;} 
        } return temp;
    }
}
```
['Array', 'Java']