Sometimes I feel like Python is almost cheating

  • 0

    With stuff like for else and no need to check for overflow, coding problems like this is so easy.

    def smallestFactorization(self, a):
        val = ''
        while a != 1:
            for i in range(9,1,-1):
                if not a%i:
                    a /= i
                    val += str(i)
                return 0
        val = int(val[::-1])
        return val if val <= 2**31 else 0

  • 0

    @david120 I just get started with Python, and I totally agree. Python makes you focus more on the problem itself instead of the implementation.

    The code seems to have an edge case a = 1 to handle. How about initialize val as
    val = '' if a > 1 else '1'

Log in to reply

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