728x90
문제 : https://leetcode.com/problems/letter-combinations-of-a-phone-number/
난이도 : Medium
풀이
class Solution:
def letterCombinations(self, digits: str) -> List[str]:
dict = {'2':"abc", '3':"def", '4':"ghi", '5':"jkl", '6':"mno", '7': "pqrs", '8':"tuv", '9':"wxyz"}
comb = [''] if digits else []
for d in digits:
comb = [p + q for p in comb for q in dict[d]]
return comb
728x90