美文网首页
2020-03-02 Day9 Leetcode: 17. Le

2020-03-02 Day9 Leetcode: 17. Le

作者: YueTan | 来源:发表于2020-03-03 08:55 被阅读0次
    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
    

    相关文章

      网友评论

          本文标题:2020-03-02 Day9 Leetcode: 17. Le

          本文链接:https://www.haomeiwen.com/subject/rgmflhtx.html