From 555fa8bb5f8475e30d9dcda60277bee6bb2c7096 Mon Sep 17 00:00:00 2001 From: "J.M. Dana" Date: Sun, 4 Oct 2020 22:11:05 +0200 Subject: [PATCH] Solution for 0017_Letter_Combinations_of_a_Phone_Number --- ...7_Letter_Combinations_of_a_Phone_Number.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LeetCode/0017_Letter_Combinations_of_a_Phone_Number.py diff --git a/LeetCode/0017_Letter_Combinations_of_a_Phone_Number.py b/LeetCode/0017_Letter_Combinations_of_a_Phone_Number.py new file mode 100644 index 0000000..e44ffe4 --- /dev/null +++ b/LeetCode/0017_Letter_Combinations_of_a_Phone_Number.py @@ -0,0 +1,19 @@ +import itertools +from typing import List + +class Solution: + def letterCombinations(self, digits: str) -> List[str]: + keyboard = { + '2': "abc", + '3': "def", + '4': "ghi", + '5': "jkl", + '6': "mno", + '7': "pqrs", + '8': "tuv", + '9': "wxyz", + } + + pressed = [keyboard[c] for c in digits] + + return [''.join(p) for p in itertools.product(*pressed) if p != ()] \ No newline at end of file