-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniqueMorseCode.java
More file actions
33 lines (26 loc) · 954 Bytes
/
UniqueMorseCode.java
File metadata and controls
33 lines (26 loc) · 954 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
package String;
import java.util.HashMap;
import java.util.Map;
/**
* Author - archit.s
* Date - 14/08/18
* Time - 11:45 AM
*/
public class UniqueMorseCode {
public int uniqueMorseRepresentations(String[] words) {
String[] morse = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
Map<String, Integer> map = new HashMap<>();
for (String word : words) {
StringBuilder temp = new StringBuilder();
for (int i = 0; i < word.length(); i++) {
temp.append(morse[word.charAt(i) - 'a']);
}
map.put(temp.toString(), 1);
}
return map.size();
}
public static void main(String[] args) {
String[] input = {"archit", "singla"};
System.out.println(new UniqueMorseCode().uniqueMorseRepresentations(input));
}
}