HTMLify
LootCode - Letter Combinations of a Phone Number - Python
Views: 332 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | class Solution: def letterCombinations(self, digits: str) -> List[str]: pad = { "2": "abc", "3": "def", "4": "ghi", "5": "jkl", "6": "mno", "7": "pqrs", "8": "tuv", "9": "xwyz" } if not digits: return [] if len(digits) == 1: return list(pad[digits]) combs = [] d = digits[0] loc = self.letterCombinations(digits[1:]) for l in pad[d]: for c in loc: combs.append(l + c) return combs |