Python 3   ||   6 lines, iteration  ||   T/S: 99% /  52%
[https://leetcode.com/problems/apply-operations-to-an-array/submissions/1166861606/?submissionId=1166861050)updateI could be wrong, but I think that time comple
```Python3 []
class Solution:
    def applyOperations(self, nums: List[int]) -> List[int]:

        for i in range(len(nums)-1):
            if nums[i] == nums[i+1]:
                nums[i]*= 2
                nums[i + 1] = 0   # <-- performing the "operation."  
      
        nums.sort(key=lambda x: x == 0)   # Sorting on a boolean key: False, then True
        
        return nums 
```
```cpp []
class Solution {
public:
    std::vector<int> applyOperations(std::vector<int>& nums) {
        int n = nums.size();

        // Perform the operation
        for (int i = 0; i < n - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                nums[i] *= 2;
                nums[i + 1] = 0;
            }
        }

        // Move all zeros to the end while maintaining order
        std::stable_partition(nums.begin(), nums.end(), [](int x) { return x != 0; });

        return nums;
    }
};
```
```java []
class Solution {
    public int[] applyOperations(int[] nums) {
        int n = nums.length;

        // Perform the operation
        for (int i = 0; i < n - 1; i++) {
            if (nums[i] == nums[i + 1]) {
                nums[i] *= 2;
                nums[i + 1] = 0;
            }
        }

        // Move all zeros to the end while maintaining order
        int[] result = new int[n];
        int index = 0;

        // First, copy non-zero elements
        for (int num : nums) {
            if (num != 0) {
                result[index++] = num;
            }
        }

        // Remaining elements will be zeros (no need to explicitly set them)
        return result;
    }

}

```

[https://leetcode.com/problems/apply-operations-to-an-array/submissions/1166861606/?submissionId=1166861050)

[update](https://leetcode.com/problems/apply-operations-to-an-array/submissions/1558649597/?submissionId=1166861050)

I could be wrong, but I think that time complexity is *O*(*N* log *N*) and space complexity is *O*(1), in which *N* ~ `len(nums)`.
['C++', 'Java', 'Python3']