python solution easy to understand


  • 0
    X
    class Solution(object):
        def integerBreak(self, n):
            """
            :type n: int
            :rtype: int
            """
            g = 0
            if n == 2:
                g = 1
            if n == 3:
                g = 2
            if n>3 and n%3 == 0:
                g = 3**(n/3)
            if n>3 and n%3 != 0:
                for i in range(n):
                    if (n-2*i)%3 == 0:
                        g = (2**i)*(3**((n-2*i)/3))
                        break
                    else:
                        continue
            return g
    

Log in to reply
 

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