Simple solution,O(1) in python


  • 0
    class solution(object): 
       def integerBreak(self, n):
            """
            :type n: int
            :rtype: int
            """
            if n == 2:
                return 1
            elif n == 3:
                return 2
            else:
                return (3**(n / 3)) * 2 if n % 3 == 2 else (3 ** (n / 3 - 1)) * 4 if n % 3 == 1 else 3 ** (n / 3)

Log in to reply
 

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