auto commit
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
## 题目链接
|
||||
|
||||
[Leetcode](https://leetcode.com/problems/integer-break/description/)
|
||||
[牛客网](https://www.nowcoder.com/practice/57d85990ba5b440ab888fc72b0751bf8?tpId=13&tqId=33257&tab=answerKey&from=cyc_github)
|
||||
|
||||
## 题目描述
|
||||
|
||||
@ -37,7 +37,7 @@ return 36 (10 = 3 + 3 + 4)
|
||||
继续拆成更大的绳子可以发现都比拆成 2 和 3 的效果更差,因此我们只考虑将绳子拆成 2 和 3,并且优先拆成 3,当拆到绳子长度 n 等于 4 时,也就是出现 3+1,此时只能拆成 2+2。
|
||||
|
||||
```java
|
||||
public int integerBreak(int n) {
|
||||
public int cutRope(int n) {
|
||||
if (n < 2)
|
||||
return 0;
|
||||
if (n == 2)
|
||||
@ -55,7 +55,7 @@ public int integerBreak(int n) {
|
||||
### 动态规划
|
||||
|
||||
```java
|
||||
public int integerBreak(int n) {
|
||||
public int cutRope(int n) {
|
||||
int[] dp = new int[n + 1];
|
||||
dp[1] = 1;
|
||||
for (int i = 2; i <= n; i++)
|
||||
|
Reference in New Issue
Block a user