• 문제 링크
Unique Morse Code Words - LeetCode
Can you solve this real interview question? Unique Morse Code Words - International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: * 'a' maps to ".-", * 'b' maps to "-...", * 'c' maps to "-.-.
leetcode.com
• 풀이 코드
import java.util.HashSet;
import java.util.Set;
public class Solution {
public int uniqueMorseRepresentations(String[] words) {
String[] arr = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
Set<String> set = new HashSet<>();
for (String s : words) {
StringBuilder sb = new StringBuilder();
for (char c : s.toCharArray()) sb.append(arr[c - 'a']);
set.add(sb.toString());
}
return set.size();
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 812. Largest Triangle Area - Java (0) | 2026.10.18 |
|---|---|
| [LeetCode] 806. Number of Lines To Write String - Java (0) | 2026.10.17 |
| [LeetCode] 796. Rotate String - Java (0) | 2026.10.15 |
| [LeetCode] 783. Minimum Distance Between BST Nodes - Java (0) | 2026.10.14 |
| [LeetCode] 771. Jewels and Stones - Java (0) | 2026.10.13 |
댓글