python - mobile

  • 0
    class Solution(object):
        def do_letter_combos(self, letters, prefix, answer):
            if not letters:
                for c in letters[0]:
                    self.do_letter_combos(letters[1:], prefix + [c], answer)
            return answer
        def letterCombinations(self, digits):
            :type digits: str
            :rtype: List[str]
            if not digits:
                return []
            letters = {}
            letters['2'] = 'abc'
            letters['3'] = 'def'
            letters['4'] = 'ghi'
            letters['5'] = 'jkl'
            letters['6'] = 'mno'
            letters['7'] = 'pqrs'
            letters['8'] = 'tuv'
            letters['9'] = 'wxyz'
            return self.do_letter_combos([letters[d] for d in digits], [], [])

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.