parent
90ed55b5da
commit
c8cc5b5120
|
|
@ -161,6 +161,25 @@ class Solution {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```java
|
||||||
|
// DP 方法
|
||||||
|
class Solution {
|
||||||
|
public int maxSubArray(int[] nums) {
|
||||||
|
int ans = Integer.MIN_VALUE;
|
||||||
|
int[] dp = new int[nums.length];
|
||||||
|
dp[0] = nums[0];
|
||||||
|
ans = dp[0];
|
||||||
|
|
||||||
|
for (int i = 1; i < nums.length; i++){
|
||||||
|
dp[i] = Math.max(dp[i-1] + nums[i], nums[i]);
|
||||||
|
ans = Math.max(dp[i], ans);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
```python
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue