您的位置:首页 > 编程语言 > Python开发

leetcode Letter Combinations of a Phone Number python

2015-11-21 00:00 751 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: