首页 > 其他 > 详细

LeetCode(17)Letter Combinations of a Phone Number

时间:2017-07-22 12:45:41      阅读:263      评论:0      收藏:0      [点我收藏+]

题目如下:

技术分享

Python代码:

class Solution(object):
    def letterCombinations(self, digits):
        """
        :type digits: str
        :rtype: List[str]
        """
        if not digits:
            return []
        dic = {2:abc,3:def,4:ghi,5:jkl,6:mno,7:pqrs,8:tuv,9:wxyz}
        result = []
        self.helper(digits,dic,0,"",result)
        return result
    
    def helper(self,digits,dic,index,temp,result):
        if index==len(digits):
            result.append(temp)
        else:
            s = dic[digits[index]]
            for i in s:
                temp += i
                self.helper(digits,dic,index+1,temp,result)
                temp = temp[:-1]

 

LeetCode(17)Letter Combinations of a Phone Number

原文:http://www.cnblogs.com/CQUTWH/p/7220773.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!