diff --git a/0017-letter-combinations-of-a-phone-number/0017-letter-combinations-of-a-phone-number.py b/0017-letter-combinations-of-a-phone-number/0017-letter-combinations-of-a-phone-number.py new file mode 100644 index 0000000..e67911a --- /dev/null +++ b/0017-letter-combinations-of-a-phone-number/0017-letter-combinations-of-a-phone-number.py @@ -0,0 +1,26 @@ +class Solution: + def letterCombinations(self, digits: str) -> List[str]: + mapping = { + "2": "abc", + "3": "def", + "4": "ghi", + "5": "jkl", + "6": "mno", + "7": "pqrs", + "8": "tuv", + "9": "wxyz" + } + + curr = [""] + next = [] + + for digit in digits: + for prefix in curr: + for newChar in mapping[digit]: + next.append(f"{prefix}{newChar}") + curr = next + next = [] + + return curr + + \ No newline at end of file