Skip to content

Instantly share code, notes, and snippets.

@florinutz
Created November 7, 2019 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florinutz/d9b48394eb41c240fc215691edf04cb2 to your computer and use it in GitHub Desktop.
Save florinutz/d9b48394eb41c240fc215691edf04cb2 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
strs := []string{"a", "b", "c"}
strs2 := []string{"b", "c", "d"}
fmt.Println(intersection(strs, strs2))
}
func intersection(strs1 []string, str2 []string) (result []string) {
var m = map[string]bool{}
for _, v := range append(strs1, str2...) {
if _, ok := m[v]; ok {
result = append(result, v)
} else {
m[v] = true
}
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment