-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathleetCode_17.py
More file actions
37 lines (30 loc) · 847 Bytes
/
leetCode_17.py
File metadata and controls
37 lines (30 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Solution:
nc = [ ['a','b','c'],
['d','e','f'],
['g','h','i'],
['j','k','l'],
['m','n','o'],
['p','q','r','s'],
['t','u','v'],
['w','x','y','z'] ]
def letterCombinations(self, digits):
"""
:type digits: str
:rtype: List[str]
"""
if not digits: return []
ansf = list()
curCs = ''
self.nt(ansf,curCs,digits)
return ansf
def nt(self,ans,curC,d):
if len(d) == 1:
for x in self.nc[int(d[0])-2]:
curc = curC
curc = curc + x
ans.append(curc)
else:
for x in self.nc[int(d[0])-2]:
curC = curC + x
self.nt(ans,curC,d[1:])
curC = curC[:len(curC)-1]