Answers for "intersection in go"

Go
0

intersection in go

s_intersection := map[int]bool{}
if len(s1) > len(s2) {
  s1, s2 = s2, s1 // better to iterate over a shorter set
}
for k,_ := range s1 { 
  if s2[k] {
    s_intersection[k] = true
  }
}
Posted by: Guest on October-30-2021

Browse Popular Code Answers by Language