Python solution use itertools, one line


  • 0
    L

    '''
    class Solution(object):
    def letterCombinations(self, digits):
    """
    :type digits: str
    :rtype: List[str]
    """
    if not digits:
    return []
    import itertools
    num_dict = {'2': 'abc',
    '3': 'def',
    '4': 'ghi',
    '5': 'jkl',
    '6': 'mno',
    '7': 'pqrs',
    '8': 'tuv',
    '9': 'wxyz'}
    return list(''.join(i) for i in itertools.product(*[num_dict[i] for i in digits]))
    '''


Log in to reply
 

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