Added leetcode exercise 17
This commit is contained in:
parent
cf785e707d
commit
749f7846a5
21
leetcode/17_letter_combinations_of_a_phone_number.py
Normal file
21
leetcode/17_letter_combinations_of_a_phone_number.py
Normal file
@ -0,0 +1,21 @@
|
||||
class Solution:
|
||||
def letterCombinations(self, digits: str) -> List[str]:
|
||||
if len(digits) == 0:
|
||||
return []
|
||||
|
||||
options = {
|
||||
'2': ('a', 'b', 'c'),
|
||||
'3': ('d', 'e', 'f'),
|
||||
'4': ('g', 'h', 'i'),
|
||||
'5': ('j', 'k', 'l'),
|
||||
'6': ('m', 'n', 'o'),
|
||||
'7': ('p', 'q', 'r', 's'),
|
||||
'8': ('t', 'u', 'v'),
|
||||
'9': ('w', 'x', 'y', 'z')
|
||||
}
|
||||
|
||||
pools = (options[digit] for digit in digits)
|
||||
result = [""]
|
||||
for pool in pools:
|
||||
result = [x+y for x in result for y in pool]
|
||||
return result
|
Loading…
x
Reference in New Issue
Block a user