Created
August 18, 2017 23:13
-
-
Save farkwun/53eb84939db390a81ebe7ae43575f499 to your computer and use it in GitHub Desktop.
343. Integer Break
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://leetcode.com/problems/integer-break/description/ | |
class Solution(object): | |
def integerBreak(self, n): | |
""" | |
:type n: int | |
:rtype: int | |
""" | |
if n == 1 or n == 2: | |
return 1 | |
if n == 3: | |
return 2 | |
ans = 1 | |
while n > 4: | |
ans *= 3 | |
n -= 3 | |
ans *= n | |
return ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found this solution very popular and helpful:
https://www.youtube.com/watch?v=uJ7XF4D-kEk&ab_channel=EricProgramming