Python: Using itertools.product


  • 0
    D

    I used itertools.product
    Thanks to @StefanPochmann

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

Log in to reply
 

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