My LeetCode grinding. Trying to do a problem a day.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

main.py 677B

12345678910111213141516171819
  1. class Solution:
  2. def uniqueMorseRepresentations(self, words):
  3. transforms = dict()
  4. for word in words:
  5. t = ""
  6. for c in word:
  7. t += self.morseFromChar(c)
  8. transforms[t] = True
  9. return len(transforms.keys())
  10. def morseFromChar(self, c):
  11. morseMap = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
  12. return morseMap[ord(c)-97]
  13. s = Solution()
  14. print("Expected: 2")
  15. print("Got:", s.uniqueMorseRepresentations(["gin", "zen", "gig", "msg"]))