We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5604da4 commit e10ac7cCopy full SHA for e10ac7c
notes/剑指offer面试题14--剪绳子.md
@@ -59,8 +59,6 @@ public static int maxProductAfterCutting(int length) {
59
60
这道题我们按照下面的做法就能得到最优解:如果绳子长度n >= 5,就不断分出长度为3的绳子,如果最后只剩下长度为1的绳子,退一步,将得到长度为4的绳子,然后将这长度为4的绳子分成`2*2`(这样分是因为`2*2`大于原来的`3*1`);因此n = 4时不能分出长度为3的绳子,而n = 2,n = 3的最优解可直接返回。
61
62
-当`n >=5`时,满足该不等式的满足`i*(n-i) > n`的只有`2*(n-2) > n`以及`3*(n-3) > n`,注意i+n-2 = n,也就是说分出的两个相乘的数要满足和为n,且给定同样的n,`3*(n-3)`的值更大,这就是为什么要不断分出长度为3的绳子的原因。
63
-
64
基于此写出代码。
65
66
```java
@@ -95,4 +93,4 @@ public static int maxProductAfterCutting2(int length) {
95
93
96
94
by @sunhaiyu
97
98
-2017.12.19
+2017.12.19
0 commit comments