문제 이해

입력

출력

요구 사항


문제 풀이


Code

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