funcSliceDifferenceInt(A, B []int)[]int{iflen(A)<1||len(B)<1{return A
}
result :=make([]int,0)// 去重
flagMap :=make(map[int]bool,0)for_, a :=range A {if_, ok := flagMap[a]; ok {continue}
flagMap[a]=true
flag :=truefor_, b :=range B {if b == a {
flag =falsebreak}}if flag {
result =append(result, a)}}return result
}
求两个int切片的交集
funcSliceIntersectionInt(A, B []int)[]int{iflen(A)<1||len(B)<1{return[]int{}}
result :=make([]int,0)// 去重
flagMap :=make(map[int]bool,0)for_, a :=range A {if_, ok := flagMap[a]; ok {continue}
flagMap[a]=truefor_, b :=range B {if b == a {
result =append(result, a)break}}}return result
}
求两个int切片的并集
funcSliceUnionInt(A, B []int)[]int{
result :=make([]int,0)// 去重
flagMap :=make(map[int]bool,0)
A =append(A, B...)for_, a :=range A {if_, ok := flagMap[a]; ok {continue}
flagMap[a]=true
result =append(result, a)}return result
}