package main
func arrUnique(arr []int)[]int{
i := 0
length := len(arr)
for j:=1;j<length;{
j++
if arr[i+1] != arr[j]{
arr[i+1] = arr[j]
i++
}
}
length +1
return arr[:length]
}
func main(){
arr := []int{1, 1, 1, 2, 3, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 10, 10}
fmt.Println(arr)
res := arrUnique(arr)
fmt.Println(res)
}
结果:
image.png
网友评论