贪心
class Solution {
public int maxSubArray(int[] nums) {
int res = Integer.MIN_VALUE;
int count = 0;
for(int i = 0; i < nums.length; i++){
count += nums[i];
// 区间终止:如果count取到最大值函数及时记录
if(count > res){
res = count;
}
// count一旦加上nums[i]变为负数,那么就应该从nums[i+1]开始从0累计count
if(count < 0){
count = 0;
}
}
return res;
}
}