class Solution {
public int maxSubArray(int[] nums) {
int pre = 0, result = nums[0];
for (int num : nums) {
pre += num;
result = Math.max(result, pre);
if (pre < 0) {
pre = 0;
}
}
return result;
}
}
08-05
177
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-21
312
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-29
756
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)