mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 03:27:07 +00:00
Time: 20 ms (78.79%), Space: 13.4 MB (66.30%) - LeetHub
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
class Solution(object):
|
||||
def letterCombinations(self, digits):
|
||||
"""
|
||||
:type digits: str
|
||||
:rtype: List[str]
|
||||
"""
|
||||
numToLetters = {
|
||||
2: "abc",
|
||||
3: "def",
|
||||
4: "ghi",
|
||||
5: "jkl",
|
||||
6: "mno",
|
||||
7: "pqrs",
|
||||
8: "tuv",
|
||||
9: "wxyz"
|
||||
}
|
||||
|
||||
combos = [""]
|
||||
for d in digits:
|
||||
comsToAdd = []
|
||||
for l in numToLetters[int(d)]:
|
||||
for combo in combos:
|
||||
comsToAdd.append(combo + l)
|
||||
combos = comsToAdd
|
||||
|
||||
return [] if combos == [""] else combos
|
||||
|
||||
Reference in New Issue
Block a user