My kotlin solution with time O(N) and space O(1)
The idea is to simulate the process. We can eliminate the shifting of zeros by clearing the existing values and assigning nonzero values to the front of nums du
The idea is to simulate the process. We can eliminate the shifting of zeros by clearing the existing values and assigning nonzero values to the front of nums during the iteration.

Below are my implementations,
```kotlin []
class Solution {
    // Complexity:
    // Time O(N) and Space O(1) where N is the length of `nums`.
    fun applyOperations(nums: IntArray): IntArray {
        var tail = 0 // The index in `nums` to place the next nonzero value
        var currValue = 0

        for ((i, nextValue) in nums.withIndex()) {
            nums[i] = 0

            if (currValue == 0) {
                currValue = nextValue
                continue
            }

            if (currValue == nextValue) {
                nums[tail] = currValue * 2
                currValue = 0
            } else {
                nums[tail] = currValue
                currValue = nextValue
            }
            tail++
        }
        if (currValue != 0) {
            nums[tail] = currValue
            tail++
        }
        return nums
    }
}

```

```golang []
// Complexity:
// Time O(N) and Space O(1) where N is the length of nums.
func applyOperations(nums []int) []int {
	tail := 0 // The index in nums to place the next nonzero value
	currValue := 0

	for i, nextValue := range nums {
		nums[i] = 0

		if currValue == 0 {
			currValue = nextValue
			continue
		}

		if currValue == nextValue {
			nums[tail] = currValue * 2
			currValue = 0
		} else {
			nums[tail] = currValue
			currValue = nextValue
		}
		tail++
	}
	if currValue != 0 {
		nums[tail] = currValue
		tail++
	}
	return nums
}

```
['Go', 'Kotlin']