Python solution using FIFO


  • 0
    C
    def letterCombinations(self, digits):
    
        if digits == "":
            return []
            
        ans = []
        mapping = ["0", "1", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]
        ans.append("")
        
        digits = str(digits)
        
        for i in range(len(digits)) :
            x = mapping[int(digits[i])]
    
            while len(ans[0]) == i :
                t = ans.pop(0)
                for s in x :
                    ans.append(t+s)
            
        return ans

Log in to reply
 

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