Simple iterative python


  • 0
    S

    Figure number of '3's >= n-4. Then figure number of 2's.

    class Solution(object):
        def integerBreak(self, n):
            """
            :type n: int
            :rtype: int
            """
            if n == 2: return 1
            if n == 3: return 2
            product = 1
            while n>4:
                product *=3
                n -= 3
            if n == 2:return 2*product
            if n == 3:return 3*product
            if n == 4:return 4*product
    

Log in to reply
 

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