Simple Python code


  • 0

    '''
    class Solution(object):
    def letterCombinations(self, digits):
    """
    :type digits: str
    :rtype: List[str]
    """
    if(len(digits) == 0):
    return []
    set = {'1': '*', '2': 'abc', '3': 'def', '4': 'ghi', '5': 'jkl', '6': 'mno',
    '7': 'pqrs', '8': 'tuv', '9': 'wxyz', '0': ' '}
    ans, s = [], [set[key] for key in digits]
    ans += s
    for i in range(1,len(s)):
    ans = self.mul(ans, s[i])
    return ans
    def mul(self,list,s):
    ans = []
    for i in range(len(list)):
    for j in range(len(s)):
    ans.append(list[i] + s[j])
    return ans
    '''


Log in to reply
 

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