My Python Solution using List Comprehensions


  • 0
    L
    class Solution(object):
        def letterCombinations(self, digits):
            """
            :type digits: str
            :rtype: List[str]
            """
            if digits == "":
                return []
            dict_d = {'1': ' ', '2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', '6': 'mno', '7': 'pqrs', '8': 'tuv', '9': 'wxyz', '0': '*'}
            result = list(dict_d[digits[0]])
            for i in range(1, len(digits)):
                result = [x + y for x in result for y in dict_d[digits[i]]]
            return result
    

Log in to reply
 

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