leetcode Letter Combinations of a Phone Number python

class Solution(object):
    def letterCombinations(self, digits):
        """
        :type digits: str
        :rtype: List[str]
        """
        if len(digits) <= 0:
            return list()
        alpha = ["","1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"]
        res=[]
        word=[]
        def dfs(cur):
            if cur >= len(digits):
                res.append(''.join(word))
            else:
                for x in alpha[int(digits[cur])-(int)('0')]:
                    word.append(x)
                    dfs(cur+1)
                    word.pop()
        dfs(0)
        
        return res

@link http://blog.csdn.net/hcbbt/article/details/44061179

posted @ 2015-11-21 00:00  hao.ma  阅读(111)  评论(0编辑  收藏  举报