From 453a398b7d29340832c8eb6cd69590a7a14e4877 Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Fri, 15 Jul 2022 22:51:32 -0400 Subject: [PATCH] Time: 20 ms (78.79%), Space: 13.4 MB (66.30%) - LeetHub --- ...7-letter-combinations-of-a-phone-number.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 17-letter-combinations-of-a-phone-number/17-letter-combinations-of-a-phone-number.py diff --git a/17-letter-combinations-of-a-phone-number/17-letter-combinations-of-a-phone-number.py b/17-letter-combinations-of-a-phone-number/17-letter-combinations-of-a-phone-number.py new file mode 100644 index 0000000..e527882 --- /dev/null +++ b/17-letter-combinations-of-a-phone-number/17-letter-combinations-of-a-phone-number.py @@ -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 + \ No newline at end of file