Skip to content

Commit 74abf06

Browse files
committed
leetcode.com 17. Letter Combinations of a Phone Number
문제 링크: https://leetcode.com/problems/letter-combinations-of-a-phone-number
1 parent fff8d93 commit 74abf06

File tree

1 file changed

+33
-0
lines changed
  • leetcode.com 17. Letter Combinations of a Phone Number v2

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def letterCombinations(self, digits: str) -> List[str]:
6+
dict = {}
7+
dict['2'] = ['a', 'b', 'c']
8+
dict['3'] = ['d', 'e', 'f']
9+
dict['4'] = ['g', 'h', 'i']
10+
dict['5'] = ['j', 'k', 'l']
11+
dict['6'] = ['m', 'n', 'o']
12+
dict['7'] = ['p', 'q', 'r', 's']
13+
dict['8'] = ['t', 'u', 'v']
14+
dict['9'] = ['w', 'x', 'y', 'z']
15+
16+
queue = [['']]
17+
queue2 = []
18+
19+
for d in digits:
20+
for prev in queue:
21+
for new in dict[d]:
22+
queue2.append(prev + [new])
23+
24+
queue = queue2
25+
queue2 = []
26+
27+
answer = []
28+
for q in queue:
29+
a = ''.join(q)
30+
if a != '':
31+
answer.append(a)
32+
33+
return answer

0 commit comments

Comments
 (0)