Last active
October 11, 2018 22:57
-
-
Save lienista/5f7cc306a1f699dc9e2676aa5c7f30ac to your computer and use it in GitHub Desktop.
(Algorithms in Javascript) Leetcode 343. Integer Break - Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.
This file contains hidden or 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
| const integerBreak = (n) => { | |
| if(n<=3) return n-1; | |
| if(n%3===0) return Math.pow(3, n/3); | |
| if(n%3===1) return 4*Math.pow(3, (n-4)/3); | |
| return 2*Math.pow(3,parseInt(n/3)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment