aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-12-05 08:42:16 +0000
committerterminaldweller <thabogre@gmail.com>2022-12-05 08:42:16 +0000
commit262e6c16bd6c45166738ba520fc58520ceb491c8 (patch)
tree703bb9f2fc8abe6c788aeed5d6b4460d2da174bb
parent1 (diff)
downloadleetcode-262e6c16bd6c45166738ba520fc58520ceb491c8.tar.gz
leetcode-262e6c16bd6c45166738ba520fc58520ceb491c8.zip
17
-rwxr-xr-x17-go/main.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/17-go/main.py b/17-go/main.py
new file mode 100755
index 0000000..6e997ad
--- /dev/null
+++ b/17-go/main.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+from typing import List
+
+
+class Solution:
+ def letterCombinations(self, digits: str) -> List[str]:
+ combinations: List[str] = []
+ if digits is None or len(digits) == 0:
+ return combinations
+
+ def find_combinations(
+ combinations,
+ digits,
+ previous,
+ index,
+ letters_numbers_mapping,
+ ):
+ if index == len(digits):
+ combinations.append(previous)
+ return
+ letters = letters_numbers_mapping[int(digits[index])]
+ for i in range(0, len(letters)):
+ find_combinations(
+ combinations,
+ digits,
+ previous + letters[i],
+ index + 1,
+ letters_numbers_mapping,
+ )
+
+ letters_numbers_mapping = [
+ "",
+ "",
+ "abc",
+ "def",
+ "ghi",
+ "jkl",
+ "mno",
+ "pqrs",
+ "tuv",
+ "wxyz",
+ ]
+ find_combinations(combinations, digits, "", 0, letters_numbers_mapping)
+ return combinations
+
+
+def main():
+ solution = Solution()
+ print(solution.letterCombinations("23"))
+
+
+if __name__ == "__main__":
+ main()