Skip to content

Commit fd7020d

Browse files
committed
三刷343
1 parent bcc75cb commit fd7020d

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

docs/0343-integer-break.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ include::{sourcedir}/_0343_IntegerBreak.java[tag=answer]
5454
include::{sourcedir}/_0343_IntegerBreak_2.java[tag=answer]
5555
----
5656
--
57+
58+
三刷::
59+
+
60+
--
61+
[{java_src_attr}]
62+
----
63+
include::{sourcedir}/_0343_IntegerBreak_3.java[tag=answer]
64+
----
65+
--
5766
====
5867

5968
== 参考资料

logbook/202406.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,10 @@
595595
|{doc_base_url}/0231-power-of-two.adoc[题解]
596596
|位运算, `n & (n - 1)` 或约数
597597

598+
|{counter:codes}
599+
|{leetcode_base_url}/integer-break/[343. Integer Break^]
600+
|{doc_base_url}/0343-integer-break.adoc[题解]
601+
|动态规划,数学分析也可以看一下:怎么样计算自然底数 `e` 的值?
598602

599603
|===
600604

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.diguage.algo.leetcode;
2+
3+
public class _0343_IntegerBreak_3 {
4+
// tag::answer[]
5+
/**
6+
* @author D瓜哥 · https://www.diguage.com
7+
* @since 2024-09-15 20:47:03
8+
*/
9+
public int integerBreak(int n) {
10+
int[] dp = new int[n + 1];
11+
for (int i = 2; i <= n; i++) {
12+
int max = -1;
13+
for (int j = 1; j < i / 2 + 1; j++) {
14+
max = Math.max(Math.max(max, j * (i - j)), j * dp[i - j]);
15+
}
16+
dp[i] = max;
17+
}
18+
return dp[n];
19+
}
20+
// end::answer[]
21+
}

0 commit comments

Comments
 (0)