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