2020-03-02 Day9 Leetcode: 17. Le

2020-03-03  本文已影响0人  YueTan
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
上一篇下一篇

猜你喜欢

热点阅读