Files
LeetCode-Go/leetcode/0884.Uncommon-Words-from-Two-Sentences/884. Uncommon Words from Two Sentences.go
2020-08-07 17:06:53 +08:00

19 lines
325 B
Go

package leetcode
import "strings"
func uncommonFromSentences(A string, B string) []string {
m, res := map[string]int{}, []string{}
for _, s := range []string{A, B} {
for _, word := range strings.Split(s, " ") {
m[word]++
}
}
for key := range m {
if m[key] == 1 {
res = append(res, key)
}
}
return res
}