第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Golang 從切片追加函數(shù)“已評(píng)估但未使用”中刪除重復(fù)整數(shù)

Golang 從切片追加函數(shù)“已評(píng)估但未使用”中刪除重復(fù)整數(shù)

Go
慕哥6287543 2023-04-24 16:01:58
我無(wú)法讓這個(gè) Go lang 測(cè)試程序運(yùn)行。編譯器在下面的 append() 函數(shù)調(diào)用中不斷給出錯(cuò)誤,并顯示“已評(píng)估但未使用”錯(cuò)誤。我不知道為什么。package mainimport (    "fmt")func removeDuplicates(testArr *[]int) int {    prevValue := (*testArr)[0]    for curIndex := 1; curIndex < len((*testArr)); curIndex++ {        curValue := (*testArr)[curIndex]        if curValue == prevValue {            append((*testArr)[:curIndex], (*testArr)[curIndex+1:]...)        }        prevValue = curValue    }    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 回答

?
qq_遁去的一_1

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)

}


查看完整回答
反對(duì) 回復(fù) 2023-04-24
?
一只斗牛犬

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊

編譯錯(cuò)誤是由于沒(méi)有從 append() 獲取返回值



查看完整回答
反對(duì) 回復(fù) 2023-04-24
  • 2 回答
  • 0 關(guān)注
  • 137 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)