Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 10dcee1

Browse files
committed
.
1 parent e30635b commit 10dcee1

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

‎backtrack/Yu/17.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Solution(object):
2+
def letterCombinations(self, string):
3+
4+
# input : "23"
5+
# output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
6+
7+
#Edge
8+
if not string:
9+
return []
10+
11+
#Global Variable
12+
self.dict = {
13+
"2":"abc",
14+
"3":"def",
15+
"4":"ghi",
16+
"5":"jkl",
17+
"6":"mno",
18+
"7":"pqrs",
19+
"8":"tuv",
20+
"9":"wxyz"
21+
}
22+
self.res = []
23+
24+
25+
# Helper function
26+
def dfs(string, index, temp):
27+
if len(temp) == len(string):
28+
self.res.append("".join(x for x in temp))
29+
return
30+
31+
for char in self.dict[string[index]]:
32+
temp.append(char)
33+
dfs(string, index+1, temp)
34+
temp.pop()
35+
36+
37+
# Function Call
38+
dfs(string, 0, [])
39+
return self.res

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /