[Leet Code] Unique Morse Code Words

Input: words = ["gin", "zen", "gig", "msg"]
Output: 2
The transformation of each word is:
"gin" -> "--...-."
"zen" -> "--...-."
"gig" -> "--...--."
"msg" -> "--...--."
There are 2 different transformations, "--...-." and "--...--.".
class Solution(object):
def uniqueMorseRepresentations(self, words):
:type words: List[str]
:rtype: int
alphabet = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
answer = {}
for i in words:
string = ""
for j in i:
string = string + alphabet[ord(j) - 97]
answer[string] = 1
return len(answer)




Learning, and posting my findings!

Love podcasts or audiobooks? Learn on the go with our new app.

Moving Averages in Python

Make your own Freeview recorder

How to install Ubuntu 20.04 and dual boot alongside Windows 10

Better data processing in Flutter

NavCoin News — September 2019

Multithreading 101

Music and Software Have More in Common Than You Think

Important definitions for business Executives - API

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!

More from Medium

[Leet Code] Maximum Number of Words Found in Sentences

Restore IP Addresses | LeetCode-93: Medium | JavaScript Implementation

Commonly Asked Java Interview Questions

Top Core Java Concepts