luoheng
10/11/2019 - 2:17 PM

uncommonFromSentences


import "strings"

func uncommonFromSentences(A string, B string) []string {
    var res []string
    words := map[string]int{}
    for _, word := range strings.Split(A, " ") {
        words[word]++
    }
    for _, word := range strings.Split(B, " ") {
        words[word]++
    }
    for word, times := range words {
        if times == 1 {
            res = append(res, word)   
        }
    }
    return res
}