class Solution:
def letterCombinations(self, digits: str) -> List[str]:
if len(digits)==0:
return ""
mapping={'2':'abc',
'3':'def',
'4':'ghi',
'5':'jkl',
'6':'mno',
'7':'pqrs',
'8':'tuv',
'9':'wxyz'}
letters=[mapping[digit] for digit in digits]
letters_result=[[i for i in lett] for lett in letters]
if len(letters)==1:
return letters_result[0]
result=letters_result[0]
for i in range(1,len(letters_result)):
new=letters_result[i]
result=[b+a for a in new for b in result]
return result
网友评论