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 90ed55b commit c8cc5b5Copy full SHA for c8cc5b5
problems/0053.最大子序和.md
@@ -161,6 +161,25 @@ class Solution {
161
}
162
```
163
164
+```java
165
+// DP 方法
166
+class Solution {
167
+ public int maxSubArray(int[] nums) {
168
+ int ans = Integer.MIN_VALUE;
169
+ int[] dp = new int[nums.length];
170
+ dp[0] = nums[0];
171
+ ans = dp[0];
172
+
173
+ for (int i = 1; i < nums.length; i++){
174
+ dp[i] = Math.max(dp[i-1] + nums[i], nums[i]);
175
+ ans = Math.max(dp[i], ans);
176
+ }
177
178
+ return ans;
179
180
+}
181
+```
182
183
Python:
184
```python
185
class Solution:
0 commit comments