Skip to content

Commit 5749a7f

Browse files
authored
Create 17-Letter-Combinations-of-a-Phone-Number.py
1 parent 7cc4e9c commit 5749a7f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def letterCombinations(self, digits: str) -> List[str]:
3+
res = []
4+
digitToChar = { "2": "abc",
5+
"3": "def",
6+
"4": "ghi",
7+
"5": "jkl",
8+
"6": "mno",
9+
"7": "qprs",
10+
"8": "tuv",
11+
"9": "wxyz" }
12+
13+
def backtrack(i, curStr):
14+
if len(curStr) == len(digits):
15+
res.append(curStr)
16+
return
17+
for c in digitToChar[digits[i]]:
18+
backtrack(i + 1, curStr + c)
19+
20+
if digits:
21+
backtrack(0, "")
22+
23+
return res

0 commit comments

Comments
 (0)