package main
import "fmt"
func main() {
array := []string{"red","black","orange","white","red","blue","blue"};
fmt.Println("old data = ",array)
afterData := noSame(array);
fmt.Println("new data = ",afterData)
}
func noSame(data []string) []string {
tempArr := data[:1];
i:= 0
for _,dat := range data {
for ; i < len(tempArr) ; i++ {
if dat == tempArr[i] {
break
}else{
}
}
if i == len(tempArr) {
tempArr = append(tempArr,dat)
}
}
return tempArr;
}
go语言-切片去重
最新推荐文章于 2024-06-05 10:49:44 发布