diff --git a/problems/0343.整数拆分.md b/problems/0343.整数拆分.md index 7295627f..3ba23e52 100644 --- a/problems/0343.整数拆分.md +++ b/problems/0343.整数拆分.md @@ -243,6 +243,29 @@ class Solution { } } ``` +贪心 +```Java +class Solution { + public int integerBreak(int n) { + // with 贪心 + // 通过数学原理拆出更多的3乘积越大,则 + /** + @Param: an int, the integer we need to break. + @Return: an int, the maximum integer after breaking + @Method: Using math principle to solve this problem + @Time complexity: O(1) + **/ + if(n == 2) return 1; + if(n == 3) return 2; + int result = 1; + while(n > 4) { + n-=3; + result *=3; + } + return result*n; + } +} +``` ### Python 动态规划(版本一)