Created
November 7, 2019 11:03
-
-
Save florinutz/d9b48394eb41c240fc215691edf04cb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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