0%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| class Solution: def __init__(self): self.path = '' self.result = [] self.dict = {} def push_dict(): self.dict[2] = 'abc' self.dict[3] = 'def' self.dict[4] = 'ghi' self.dict[5] = 'jkl' self.dict[6] = 'mno' self.dict[7] = 'pqrs' self.dict[8] = 'tuv' self.dict[9] = 'wxyz' push_dict() def letterCombinations(self, digits: str) -> List[str]: return self.letterCombinations_(digits,0) def letterCombinations_(self,digits,index) -> List[str]: if index == len(digits): return self.result target = self.dict[int(digits[index])] for i in range(0,len(target)): self.path += target[i] if index == len(digits)-1: self.result.append(self.path) print(self.result) self.letterCombinations_(digits,index+1) self.path = self.path[:-1] return self.result
|