package leetcode;

/**
 * https://leetcode.com/problems/unique-morse-code-words/
 */
public class Problem804 {
    public int uniqueMorseRepresentations(String[] words) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem804 prob = new Problem804();
        System.out.println(prob.uniqueMorseRepresentations(new String[]{"gin", "zen", "gig", "msg"})); // 2
    }
}

package leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * https://leetcode.com/problems/unique-morse-code-words/
 */
public class Problem804 {
    public int uniqueMorseRepresentations(String[] words) {
        String[] morse = new String[]{
            ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..",
            "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-",
            "-.--", "--.."};
        Set<String> set = new HashSet<>();
        for (String word : words) {
            StringBuilder sb = new StringBuilder();
            for (char c : word.toCharArray()) {
                sb.append(morse[c - 'a']);
            }
            set.add(sb.toString());
        }
        return set.size();
    }
}

Solve probem 804