---
# System prepended metadata

title: Elegant code

---

Elegant code
===

80. Remove Duplicates from Sorted Array II
```go=
func removeDuplicates(nums []int) int {
    l := len(nums)
    if l < 2 {
        return len(nums)
    }

    idx := 2
    for i := 2; i < len(nums); i++ {
        if nums[i] != nums[idx-2] {
            nums[idx] = nums[i]
            idx += 1
        }
    }
    return idx
}
```