求助,leetcode的问题?

qiuquanwu · · 925 次点击
```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
这里有中文版本的解析,可以看看,希望能帮到你:https://cloud.tencent.com/developer/doc/1101
#2