✅✅🔥BEATS 96.37% SIMPLEST PROGRAM | JAVA 🔥 Python 🔥 C++ 🔥 JS 🔥 | Simplest Program |  O(n) & O(1)
IntuitionThis method modifies the given array based on certain operations:
If two consecutive elements are equal, double the first one and set the second one to
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
This method modifies the given array based on certain operations:

- If two consecutive elements are equal, double the first one and set the second one to 0.
- Shift all non-zero elements to the left while maintaining their relative order.


# Approach
<!-- Describe your approach to solving the problem. -->
- This loop iterates through the array from index 0 to nums.length - 2.
- It checks if two consecutive elements (nums[i] and nums[i+1]) are equal.
     - If true, it doubles nums[i] and sets nums[i+1] to 0.
     - If false, it continues to the next iteration.

# Complexity
- Time complexity: **O(n)**
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: **O(1)**
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# ⬆️PLS UPVOTE
# ⬆️PLS UPVOTE
# ⬆️PLS UPVOTE


# Code
```java []
class Solution {
    public int[] applyOperations(int[] nums) {
        for(int i = 0; i < nums.length-1; i++) {
            if(nums[i] == nums[i+1]) {
                nums[i] *= 2;
                nums[i+1] = 0;
            } else {
                continue;
            }
        }

        int index = 0;
        for(int i = 0; i < nums.length; i++) {
            if(nums[i] != 0) {
                int temp = nums[index];
                nums[index] = nums[i];
                nums[i] = temp;
                index++;
            }
        }
        return nums;
    }
}
```
```Python []
class Solution:
    def applyOperations(self, nums):
        n = len(nums)
        for i in range(n - 1):
            if nums[i] == nums[i + 1]:
                nums[i] *= 2
                nums[i + 1] = 0

        index = 0
        for i in range(n):
            if nums[i] != 0:
                nums[index], nums[i] = nums[i], nums[index]
                index += 1
                
        return nums

```
```C++ []
#include <vector>
using namespace std;

class Solution {
public:
    vector<int> applyOperations(vector<int>& nums) {
        int n = nums.size();
        
        for (int i = 0; i < n - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                nums[i] *= 2;
                nums[i + 1] = 0;
            }
        }

        int index = 0;
        for (int i = 0; i < n; i++) {
            if (nums[i] != 0) {
                swap(nums[index], nums[i]);
                index++;
            }
        }
        
        return nums;
    }
};

```
```JavaScript []
var applyOperations = function(nums) {
    let n = nums.length;
    
    for (let i = 0; i < n - 1; i++) {
        if (nums[i] === nums[i + 1]) {
            nums[i] *= 2;
            nums[i + 1] = 0;
        }
    }

    let index = 0;
    for (let i = 0; i < n; i++) {
        if (nums[i] !== 0) {
            [nums[index], nums[i]] = [nums[i], nums[index]];
            index++;
        }
    }
    
    return nums;
};

```
['Two Pointers', 'Python', 'C++', 'Java', 'JavaScript']