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 48c4b15 commit f293d70Copy full SHA for f293d70
notes/Leetcode 题解.md
@@ -2391,6 +2391,20 @@ public int maxSubArray(int[] nums) {
2391
}
2392
```
2393
2394
+空间复杂度可以优化成 O(1) 空间复杂度
2395
+
2396
+```java
2397
+public int maxSubArray(int[] nums) {
2398
+ int max = nums[0];
2399
+ int oldsum = nums[0];
2400
+ for (int i = 1; i < nums.length; i++) {
2401
+ oldsum = (oldsum > 0 ? oldsum: 0) + nums[i];
2402
+ max = Math.max(max, oldsum);
2403
+ }
2404
+ return max;
2405
+}
2406
+```
2407
2408
**数组中等差递增子区间的个数**
2409
2410
[Leetcode : 413. Arithmetic Slices (Medium)](https://leetcode.com/problems/arithmetic-slices/description/)
0 commit comments