Squashed commit of the following:
commit 977b50859e760f0a8ee1c3fdcff49d7040b09bfa Author: 孙海洲 <haizhou.uestc2011@gmail.com> Date: Sun Sep 30 21:39:11 2018 +0800 Update 面试总结.md
This commit is contained in:
parent
4c891c1224
commit
405ad28538
@ -1092,18 +1092,6 @@ public int integerBreak(int n) {
|
||||
}
|
||||
```
|
||||
|
||||
### 动态规划
|
||||
|
||||
```java
|
||||
public 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; j++)
|
||||
dp[i] = Math.max(dp[i], Math.max(j * (i - j), dp[j] * (i - j)));
|
||||
return dp[n];
|
||||
}
|
||||
```
|
||||
|
||||
```python
|
||||
def integerBreak(n):
|
||||
@ -1239,6 +1227,20 @@ class Solution:
|
||||
return pow(base, exponent)
|
||||
```
|
||||
|
||||
### 动态规划
|
||||
|
||||
```java
|
||||
public 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; j++)
|
||||
dp[i] = Math.max(dp[i], Math.max(j * (i - j), dp[j] * (i - j)));
|
||||
return dp[n];
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# 参考文献
|
||||
|
||||
- 何海涛. 剑指 Offer[M]. 电子工业出版社, 2012.
|
||||
|
Loading…
x
Reference in New Issue
Block a user