Very very simple Python


  • 0
    S
    class Solution(object):
        def letterCombinations(self, digits):
            """
            :type digits: str
            :rtype: List[str]
            """
            if not digits: return []
            
            output = ['']
            hashMap = {'2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', '6': 'mno', '7': 'pqrs', '8': 'tuv', '9': 'wxyz'}
            
            for i in xrange(len(digits)-1, -1, -1):
                output = [c+s for s in output for c in hashMap[digits[i]]]
            return output
    

Log in to reply
 

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