[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.

Code Convo — Find divisors of a large number

CSV — SQL Import/Export Compilation

DBT BigQuery Performance

Get Started with ASP.NET Core and Docker

Automate your BigCommerce Theme Configuration for Different Environments

Best Practices for Salesforce CPQ Implementation

The world fastest review of AWS’s Sumerian

Porting a Virtual Reality Application

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

Recover Binary Search Tree🦽

Dynamic Programming


Minimum Depth of Binary Tree