class Solution(object):
def check(self,ret,dt,s,digits,len_digs):
s_len = len(s)
if s_len == len_digs:
ret.append(s)
return
for v in dt[digits[s_len]]:
s = s + v
self.check(ret,dt,s,digits,len_digs)
s = s[:-1]
def letterCombinations(self, digits):
"""
:type digits: str
:rtype: List[str]
"""
dt={'2':"abc",'3':"def",'4':"ghi",'5':"jkl",'6':"mno",'7':"pqrs",'8':"tuv",'9':"wxyz"}
s=""
len_digs=len(digits)
ret=[]
if len_digs > 0:
self.check(ret,dt,s,digits,len_digs)
return ret
leetcode 17 Letter Combinations of a Phone Number
Jun 11, 2017