Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1fd9204

Browse files
authoredNov 2, 2022
Create Letter Combinations of a Phone Number.py
1 parent b9c5340 commit 1fd9204

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#17. Letter Combinations of a Phone Number
2+
class Solution:
3+
def letterCombinations(self, digits: str) -> List[str]:
4+
if not digits:
5+
return []
6+
7+
ans = ['']
8+
digitToLetters = ['', '', 'abc', 'def', 'ghi',
9+
'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']
10+
11+
for d in digits:
12+
temp = []
13+
for s in ans:
14+
for c in digitToLetters[ord(d) - ord('0')]:
15+
temp.append(s + c)
16+
ans = temp
17+
18+
return ans

0 commit comments

Comments
 (0)
Please sign in to comment.