Integer BreakLeetCode 343. 12345678910public int integerBreak(int n) { int[] dp = new int[n + 1]; dp[1] = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j <= i - 1; j++) { dp[i] = Math.max(dp[i], Math.max(j * dp[i - j], j * (i - j))); } } return dp[n];} Mathematical solution12345678910111213141516171819class Solution { public int integerBreak(int n) { if(n <=3){ return n -1; } int a = n/3; int b = n % 3; //b 只能为 0 1 2 //b == 1 if(b == 1){ return (int)Math.pow(3,a - 1) * 4; }else if (b == 2){ return (int)Math.pow(3,a) * b; }else{ return (int)Math.pow(3,a); } }} Author: ChengGuangLink: https://chengguang-li.github.io/2021/08/13/Integer-Break/Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.Leetcode AlgorithmDynamic ProgrammingNext PostLongest Palindromic Subsequence Related Articles 2021-08-12Longest Palindromic Subsequence 2021-07-18Binary Tree Paths 2021-07-19Combination Sum II 2021-07-19Combination Sum 2021-07-19Combination Sum III 2021-07-19Combinations