class Solution:
def letterCombinations(self, digits: str) -> List[str]:
#先把字典写出来
d={'2':['a','b','c'],
'3':['d','e','f'],
'4':['g','h','i'],
'5':['j','k','l'],
'6':['m','n','o'],
'7':['p','q','r','s'],
'8':['t','u','v'],
'9':['w','x','y','z']}
if len(digits)==0:
return None
##backtracking
combine=[]
for ele in d[digits[0]]:
combine.append(ele)
digits=digits[1:]
while len(digits)>0:
m=[]
for c in d[digits[0]]:
for s in combine:
m.append(s+c)
combine=m
digits=digits[1:]
return combine
17. Letter Combinations of a Phone Number ##backtracking
最新推荐文章于 2022-11-19 15:55:23 发布