python solution beats 99%


  • 0
    P
    class Solution(object):
        def integerBreak(self, n):
            """
            :type n: int
            :rtype: int
            尽量的分解出 3
            """
            threeCount = 0
            if n==2:
                return 1
            elif n==3:
                return 2
            elif n==4:
                return 4
            elif n==5:
                return 6
            else:
                while n-3>=0:
                    n-=3
                    threeCount+=1
                if n==1:
                    return 3**(threeCount-1)*4
                if n==0:
                    return 3**(threeCount)
                if n==2:
                    return 3**(threeCount)*2
    
    

Log in to reply
 

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