Skip to content

Commit f293d70

Browse files
committed
auto commit
1 parent 48c4b15 commit f293d70

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

notes/Leetcode 题解.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,20 @@ public int maxSubArray(int[] nums) {
23912391
}
23922392
```
23932393

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+
23942408
**数组中等差递增子区间的个数**
23952409

23962410
[Leetcode : 413. Arithmetic Slices (Medium)](https://leetcode.com/problems/arithmetic-slices/description/)

0 commit comments

Comments
 (0)