Unique Morse Code Words

Unique Morse Code Words

class Solution {
    public int uniqueMorseRepresentations(String[] words) {
              String [] codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
        HashSet output = new HashSet();

        for ( int i = 0 ; i < words.length ; i++){
        	 StringBuilder transformation = new StringBuilder();
        	for ( int j = 0 ; j <span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>&lt; words[i].length() ; j++ ){
        		transformation.append(codes[words[i].charAt(j)-97]);
        	}
        	output.add(transformation.toString());
        }

    	return output.size();
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s