-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0804-UniqueMorseCodeWords.cs
31 lines (26 loc) · 1.03 KB
/
0804-UniqueMorseCodeWords.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
//-----------------------------------------------------------------------------
// Runtime: 92ms
// Memory Usage: 24.8 MB
// Link: https://leetcode.com/submissions/detail/327567110/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
using System.Text;
namespace LeetCode
{
public class _0804_UniqueMorseCodeWords
{
private readonly string[] MORSE_CODE = new string[] { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." };
public int UniqueMorseRepresentations(string[] words)
{
var map = new HashSet<string>();
foreach (var word in words)
{
var sb = new StringBuilder();
foreach (var ch in word)
sb.Append(MORSE_CODE[ch - 'a']);
map.Add(sb.ToString());
}
return map.Count;
}
}
}