https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/1/array/21/
请大家用go解决一下这个问题。
```go
func removeDuplicates(nums []int) []int {
if len(nums) <= 1 {
return nums
}
for i := 1; ; {
if i > len(nums)-1 {
break
}
if nums[i] == nums[i-1] {
nums = append(nums[0:i], nums[i+1:]...)
} else {
i++
}
}
return nums
}
```
#4
更多评论
```golang
func removeDuplicates(nums []int) int {
p:=0
ct:=0
idx:=0
for i,v:=range nums {
if i==0 {
p = v
ct = ct + 1
idx = idx + 1
continue
}
if v!=p {
nums[idx]=v
ct = ct +1
p = v
idx = idx + 1
}
}
return ct
}
```
#1