Solution


  • 0
    K
    class Solution:
    	def letterCombinations(self, digits):
    		if not digits:
    			return []
    
    		lookup, result = ["", "", "abc", "def", "ghi", "jkl", "mno", \
                          "pqrs", "tuv", "wxyz"], [""]
    
    		for digit in reversed(digits):
    			choices = lookup[int(digit)]
    			m, n = len(choices), len(result)
    			result += [result[i % n] for i in xrange(n, m * n)]    
    
    		for i in xrange(m * n):
    			result[i] = choices[i / n] + result[i] 
            
    		return result

Log in to reply
 

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