Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Sep 17, 2024
1 parent 41e5e47 commit c70a673
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions leetcode/884.UncommonWordsfromTwoSentences/sol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// https://leetcode.com/problems/uncommon-words-from-two-sentences/description/

package main

import (
"fmt"
"strings"
)

func uncommonFromSentences(s1 string, s2 string) []string {
words := strings.Fields(s1 + " " + s2)

wordCount := make(map[string]int)
for _, word := range words {
wordCount[word]++
}

var res []string
for word, count := range wordCount {
if count == 1 {
res = append(res, word)
}
}

return res
}

func main() {
s1 := "this apple is sweet"
s2 := "this apple is sour"
result := uncommonFromSentences(s1, s2)
fmt.Println(result)
}

0 comments on commit c70a673

Please sign in to comment.