-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution884.go
More file actions
39 lines (36 loc) · 785 Bytes
/
solution884.go
File metadata and controls
39 lines (36 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package solution884
import (
"strings"
)
// ============================================================================
// 884. Uncommon Words from Two Sentences
// URL: https://leetcode.com/problems/uncommon-words-from-two-sentences/
// ============================================================================
func uncommonFromSentences(s1 string, s2 string) []string {
sl := make([]string, 0)
m := make(map[string]int)
words1 := strings.Fields(s1)
for _, word := range words1 {
_, ok := m[word]
if !ok {
m[word] = 1
} else {
m[word]++
}
}
words2 := strings.Fields(s2)
for _, word := range words2 {
_, ok := m[word]
if !ok {
m[word] = 1
} else {
m[word]++
}
}
for k, v := range m {
if v == 1 {
sl = append(sl, k)
}
}
return sl
}