URL
https://leetcode.com/problems/uncommon-words-from-two-sentences/description/?envType=daily-question&envId=2024-09-17
Code
https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202409/uncommon_words_from_two_sentences/main.fsx
let uncommonSentences (s1: string) (s2: string) : string list =
let findUniqueWord m1 m2 acc =
m1
|> Map.fold
(fun acc k v ->
if v > 1 then
acc
else
match Map.tryFind k m2 with
| Some(_) -> acc
| None -> k :: acc)
acc
let wordCount (s: string) =
s.Split([| ' ' |]) |> Array.countBy id |> Map.ofArray
let m1, m2 = wordCount s1, wordCount s2
findUniqueWord m1 m2 [] |> findUniqueWord m2 m1