Skip to content

Commit 24b4dfd

Browse files
committed
Time: 0 ms (100%), Space: 18 MB (23%) - LeetHub
1 parent e3d11d6 commit 24b4dfd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from itertools import permutations
2+
3+
class Solution:
4+
def letterCombinations(self, digits: str) -> List[str]:
5+
if not digits:
6+
return []
7+
8+
A = {
9+
'2': 'abc',
10+
'3': 'def',
11+
'4': 'ghi',
12+
'5': 'jkl',
13+
'6': 'mno',
14+
'7': 'pqrs',
15+
'8': 'tuv',
16+
'9': 'wxyz'
17+
}
18+
19+
def backtrack(combi, next_digits):
20+
if len(next_digits) == 0:
21+
ans.append(combi)
22+
else:
23+
for i in A[next_digits[0]]:
24+
backtrack(combi + i, next_digits[1:])
25+
26+
ans = []
27+
backtrack("", digits)
28+
return ans

0 commit comments

Comments
 (0)