class Solution:
def letterCombinations(self, digits):
"""
:type digits: str
:rtype: List[str]
"""
if digits=="":
return []
digits=list(digits)
res=[]
out=[]
dicts=["abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"]
self.letterCombinationsDFS(digits,dicts,0,res,out)
return res
def letterCombinationsDFS(self,digits,dicts,level,res,out):
if level==len(digits):
aa=""
for item in out:
aa=aa+item
res.append(aa)
else:
strs=list(dicts[int(digits[level])-2])
# print(strs)
for x in range(len(strs)):
out.append(strs[x])
self.letterCombinationsDFS(digits,dicts,level+1,res,out)
out.pop()
leetcode__回溯算法__电话号码的字母组合(Python)
最新推荐文章于 2022-08-20 18:28:43 发布