Letter Combinations of a phone number_python

  • 0

    class Solution:
    def letterCombinations(self, digits):
    :type digits: str
    :rtype: List[str]
    if digits == "" or len(digits) <= 0:
    return []
    digits_dict = {"2":"abc","3":"def","4":"ghi","5":"jkl","6":"mno","7":"pqrs","8":"tuv","9":"wxyz"}
    ret = ['']
    for dig in digits:
    letters = digits_dict[dig]
    ret = [prefix+letter for prefix in ret for letter in letters]
    return ret

Log in to reply

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