我想从切片中删除切片范围,例如从“A”到“Z”中删除“A”、“B”,但我想让它更有效率(我不知道为什么在 Go 中,但在 Python 中我们可以使用 hashmap ).
下面的代码是我能得到的最接近的代码,但我错过了一些边缘情况:
func removeString(listOri []string, targetDelete []string) []string {
newitems := []string{}
for i := range listOri {
for j := range targetDelete {
if listOri [i] != targetDelete[j] {
newitems = append(newitems, listOri [i])
}
}
}
return newitems
}
listOriginal := []string{"A", "B", "C", "D"}
listDelete := []string{"A", "B"}
listNew := removeString(listOriginal, listDelete)
result = "A","B","C","C","D","D"
慕的地10843
狐的传说
相关分类