mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 03:27:07 +00:00
Time: 0 ms (100%), Space: 17.7 MB (91.79%) - LeetHub
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
class Solution:
|
||||
def letterCombinations(self, digits: str) -> List[str]:
|
||||
mapping = {
|
||||
"2": "abc",
|
||||
"3": "def",
|
||||
"4": "ghi",
|
||||
"5": "jkl",
|
||||
"6": "mno",
|
||||
"7": "pqrs",
|
||||
"8": "tuv",
|
||||
"9": "wxyz"
|
||||
}
|
||||
|
||||
curr = [""]
|
||||
next = []
|
||||
|
||||
for digit in digits:
|
||||
for prefix in curr:
|
||||
for newChar in mapping[digit]:
|
||||
next.append(f"{prefix}{newChar}")
|
||||
curr = next
|
||||
next = []
|
||||
|
||||
return curr
|
||||
|
||||
|
||||
Reference in New Issue
Block a user