首页 > 代码库 > LeetCode(17)Letter Combinations of a Phone Number
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]
LeetCode(17)Letter Combinations of a Phone Number
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。