golang 使用github.com/scylladb/go-set/strset求交并集
A := strset.NewWithSize(0)
A.Add("a","b","c","d")
B := strset.NewWithSize(0)
B.Add("a","d","e","c")
unionSet :=strset.NewWithSize(0) //交集
intersectionSet :=strset.NewWithSize(0) //并集
intersectionSet = A.Copy()
intersectionSet.Add(B.List()...)
if A.HasAny(B.List()...) || B.HasAny(A.List()...){
unionSet = A.Copy()
A.Remove(B.List()...)
unionSet .Remove(A.List()...)
}
fmt.Println("交集:",unionSet )
fmt.Println("并集:",intersectionSet)


浙公网安备 33010602011771号