Skip to content

Instantly share code, notes, and snippets.

@lienista
Last active October 11, 2018 22:57
Show Gist options
  • Select an option

  • Save lienista/5f7cc306a1f699dc9e2676aa5c7f30ac to your computer and use it in GitHub Desktop.

Select an option

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.
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