My LeetCode grinding. Trying to do a problem a day.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

problem.txt 1.2KB

12345678910111213141516171819202122232425262728
  1. International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on.
  2. For convenience, the full table for the 26 letters of the English alphabet is given below:
  3. [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
  4. Now, given a list of words, each word can be written as a concatenation of the Morse code of each letter. For example, "cba" can be written as "-.-..--...", (which is the concatenation "-.-." + "-..." + ".-"). We'll call such a concatenation, the transformation of a word.
  5. Return the number of different transformations among all words we have.
  6. Example:
  7. Input: words = ["gin", "zen", "gig", "msg"]
  8. Output: 2
  9. Explanation:
  10. The transformation of each word is:
  11. "gin" -> "--...-."
  12. "zen" -> "--...-."
  13. "gig" -> "--...--."
  14. "msg" -> "--...--."
  15. There are 2 different transformations, "--...-." and "--...--.".
  16. Note:
  17. The length of words will be at most 100.
  18. Each words[i] will have length in range [1, 12].
  19. words[i] will only consist of lowercase letters.