-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
35 lines (33 loc) · 762 Bytes
/
Solution.cs
File metadata and controls
35 lines (33 loc) · 762 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
public class Solution
{
public string[] UncommonFromSentences(string s1, string s2)
{
Dictionary<string, int> freq = [];
foreach (string word in s1.Split(" "))
{
if (freq.ContainsKey(word))
{
freq[word]++;
}
else
{
freq.Add(word, 1);
}
}
foreach (string word in s2.Split(" "))
{
if (freq.ContainsKey(word))
{
freq[word]++;
}
else
{
freq.Add(word, 1);
}
}
return freq
.Where(x => x.Value == 1)
.Select(x => x.Key)
.ToArray();
}
}