-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path101.py
33 lines (27 loc) · 763 Bytes
/
101.py
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
class Solution:
def __init__(self):
self.lettermap = {
'2': 'abc',
'3': 'def',
'4': 'ghi',
'5': 'jkl',
'6': 'mno',
'7': 'pqrs',
'8': 'tuv',
'9': 'wxyz'
}
def DFS(self, digits, index, curr):
if index == len(digits):
self.res.append(''.join(curr))
return
s = self.lettermap[digits[index]]
for c in s:
curr.append(c)
self.DFS(digits, index + 1, curr)
curr.pop()
def letterCombinations(self, digits: str) -> List[str]:
self.res = []
if len(digits) == 0:
return self.res
self.DFS(digits, 0, [])
return self.res