1 Star 0 Fork 0

marcello/go-common

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
slice.go 395 Bytes
Copy Edit Raw Blame History
marcello authored 2021-05-16 20:33 +08:00 . -
package base
// RemoveSameFromStringSlice 移除 []string 中的相同元素
func RemoveSameFromStringSlice(slice []string) []string {
var result []string
tmp := map[string]byte{} // 存放不重复主键
for _, s := range slice {
l := len(tmp)
tmp[s] = 0
if len(tmp) != l { // 加入map后,map长度变化,则元素不重复
result = append(result, s)
}
}
return result
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/marcellos/go-common.git
git@gitee.com:marcellos/go-common.git
marcellos
go-common
go-common
e809a504da49

Search