입력
digits1≤ digits.len ≤ 4출력
요구 사항
digits.len와 같음*O*(3^*N ** 4^*M*)index, path를 파라미터로 추가resindex가 digits.len와 같은지 체크
res에 path추가digits_dict[digits[index]]에서 다음에 연결할 문자열 꺼내서 for문 돌리기class Solution(object):
def letterCombinations(self, digits):
if not digits:
return []
digits_dict = {
"2": "abc",
"3": "def",
"4": "ghi",
"5": "jkl",
"6": "mno",
"7": "pqrs",
"8": "tuv",
"9": "wxyz"
}
res = []
def back_traking(index, path):
if index == len(digits):
res.append(''.join(path))
return
words = digits_dict[digits[index]]
for word in words:
path.append(word)
back_traking(index+1, path)
path.pop()
back_traking(0, [])
return res