When is it cheating to use libraries?


  • 0
    Q

    The first thing I thought when I saw this problem was, "Cross product." So I simply used python's built in itertools to do the cross product, after mapping the digits to the correct letters:

    class Solution:
        # @return a list of strings, [s1, s2]
        def letterCombinations(self, digits):
            keys={
                '2':'abc',
                '3':'def',
                '4':'ghi',
                '5':'jkl',
                '6':'mno',
                '7':'pqrs',
                '8':'tuv',
                '9':'wxyz'
                }
            possibleLetters = map(lambda s:list(keys.get(s)),digits)
            possibleCombinations = list(itertools.product(*possibleLetters))
            return list(map(''.join,possibleCombinations))
    

    Is this relying too much on the libraries provided in python?


  • 0
    S

    I would love to avoid powerful libraries.

    It is true that python always make life easier.


  • 0
    M

    I don't agree. Some builtin libraries is the part of the language. Avoid using the libraries is keeping the good part of the language away.


Log in to reply
 

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