zoukankan      html  css  js  c++  java
  • LeetCode(17)Letter Combinations of a Phone Number

    题目如下:

    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]
  • 相关阅读:
    UVa 1605
    UVa 120
    UVa 10384
    UVa 11694
    UVa 11846
    常用小函数
    【DP】:CF #319 (Div. 2) B. Modulo Sum
    类的无参方法
    类和对象
    七言
  • 原文地址:https://www.cnblogs.com/CQUTWH/p/7220773.html
Copyright © 2011-2022 走看看