2 回答

TA貢獻(xiàn)1725條經(jīng)驗(yàn) 獲得超8個(gè)贊
“已評(píng)估但未使用”錯(cuò)誤。
下面的代碼是我的想法。我認(rèn)為你的代碼不是很清楚。
package main
import (
? ? "fmt"
)
func removeDuplicates(testArr *[]int) int {
? ? m := make(map[int]bool)
? ? arr := make([]int, 0)
? ? for curIndex := 0; curIndex < len((*testArr)); curIndex++ {
? ? ? ? curValue := (*testArr)[curIndex]
? ? ? ? if has :=m[curValue]; !has {
? ? ? ? ? ? m[curValue] = true
? ? ? ? ? ? arr = append(arr, curValue)
? ? ? ? }
? ? }
? ? *testArr = arr
? ? return len(*testArr)
}
func main() {
? ? testArr := []int{0, 0, 1, 1, 1, 2, 2, 3, 3, 4}
? ? nonDupSize := removeDuplicates(&testArr)
? ? fmt.Printf("nonDupSize = %d", nonDupSize)
}
- 2 回答
- 0 關(guān)注
- 137 瀏覽
添加回答
舉報(bào)