Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
set, slice solution in Clear category for Count Morse by kurosawa4434
D = {
"a": ".-",
"b": "-...",
"c": "-.-.",
"d": "-..",
"e": ".",
"f": "..-.",
"g": "--.",
"h": "....",
"i": "..",
"j": ".---",
"k": "-.-",
"l": ".-..",
"m": "--",
"n": "-.",
"o": "---",
"p": ".--.",
"q": "--.-",
"r": ".-.",
"s": "...",
"t": "-",
"u": "..-",
"v": "...-",
"w": ".--",
"x": "-..-",
"y": "-.--",
"z": "--..",
}
def count_morse(message: str, letters: str) -> int:
p = 0
stack = [(message, set(letters))]
while stack:
rest_message, rest_letters = stack.pop()
for x in rest_letters:
if D[x] == rest_message[:len(D[x])]:
if len(rest_letters) > 1:
stack.append((rest_message[len(D[x]):], rest_letters - {x}))
else:
p += 1
return p
April 13, 2023
Comments: