Skip to content

Instantly share code, notes, and snippets.

@farkwun
Created August 18, 2017 23:13
Show Gist options
  • Save farkwun/53eb84939db390a81ebe7ae43575f499 to your computer and use it in GitHub Desktop.
Save farkwun/53eb84939db390a81ebe7ae43575f499 to your computer and use it in GitHub Desktop.
343. Integer Break
# 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
@QureshiAbraham
Copy link

QureshiAbraham commented Dec 18, 2021

I found this solution very popular and helpful:
https://www.youtube.com/watch?v=uJ7XF4D-kEk&ab_channel=EricProgramming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment