Clean Python


  • 2
    class Solution(object):
        def letterCombinations(self, digits):
            letter_table = ['', '', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']
            ans = []
            for digit in digits:
                ans = [x+ch for ch in letter_table[int(digit)] for x in ans or ['']]
            return ans

  • 0
    Q

    @lilixu Sorry~Is there anything wrong? cause I got nothing after running your code


  • 0

    @qiyusjtu
    Try this

    class Solution(object):
        def letterCombinations(self, digits):
            letter_table = ['', '', 'abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']
            ans = []
            for digit in digits:
                ans = [x+ch for ch in letter_table[int(digit)] for x in ans or ['']]
            return ans

Log in to reply
 

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