```
package main
import "fmt"
func removeDup(a []int)[]int {
i := 0
for j := 1; j < len(a); j ++ {
if a[i] != a[j] {
i ++
a[i] = a[j]
}
}
return a[:i+1]
}
func main() {
a := []int{1,1,2,2,3,3,4,5}
fmt.Println(removeDup(a))
// [1 2 3 4 5]
}
```
有疑问加站长微信联系(非本文作者))