Skip to content

Commit

Permalink
804. Unique Morse Code Words
Browse files Browse the repository at this point in the history
  • Loading branch information
liusishan committed Feb 20, 2019
1 parent 48fa850 commit 0837131
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 07-Set-and-Map/804-Unique-Morse-Code-Words/src/Solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.util.TreeSet;

/**
* @Auther: lss
* @Date: 2019/2/20 21:02
* @Description:
*/
public class Solution {

public int uniqueMorseRepresentations(String[] words) {
String[] codes = {
".-", "-...", "-.-.", "-..", ".",
"..-.", "--.", "....", "..", ".---",
"-.-", ".-..", "--", "-.", "---", ".--.",
"--.-", ".-.", "...", "-", "..-", "...-",
".--", "-..-", "-.--", "--.."};

TreeSet<String> set = new TreeSet<>();
for (String word : words) {
StringBuilder res = new StringBuilder();
for (int i = 0; i < word.length(); i++)
res.append(codes[word.charAt(i) - 'a']);

set.add(res.toString());
}
return set.size();
}
}

0 comments on commit 0837131

Please sign in to comment.