Open fockspaces opened 11 months ago
class Solution: letters = { "2": "abc", "3": "def", "4": "ghi", "5": "jkl", "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz" } def letterCombinations(self, digits: str) -> List[str]: ans = [] def helper(digits, string): if not digits: return ans.append(string) if string else None remaining_digits = digits[1:] for letter in self.letters[digits[0]]: helper(remaining_digits, string + letter) helper(digits, "") return ans