-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution804.cs
36 lines (29 loc) · 924 Bytes
/
Solution804.cs
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
using System.Text;
namespace LeetCode.Solutions;
public class Solution804
{
/// <summary>
/// 804. Unique Morse Code Words - Easy
/// <a href="https://leetcode.com/problems/unique-morse-code-words">See the problem</a>
/// </summary>
public int UniqueMorseRepresentations(string[] words)
{
var morseCodes = new string[]
{
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..",
"--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-",
"-.--", "--.."
};
var set = new HashSet<string>();
foreach (var word in words)
{
var sb = new StringBuilder();
foreach (var c in word)
{
sb.Append(morseCodes[c - 'a']);
}
set.Add(sb.ToString());
}
return set.Count;
}
}