Simple Python Solution with itertools.products

  • 0
    class Solution(object):
        def letterCombinations(self, digits):
            if len(digits) ==0:
                return []
            check = []
            dict = {'2':['a','b','c'],'3':['d','e','f'],'4':['g','h','i'],'5':['j','k','l'],'6':['m','n','o'],'7':['p','q','r','s'],'8':['t','u','v'],'9':['w','x','y','z']}
            for n in digits:
            final =  list(itertools.product(*check))
            for n in range(len(final)):
                final[n] = ''.join(final[n])
            return final

Log in to reply

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