解题思路:
class Solution {
public int maxSubArray(int[] nums) {
int res = Integer.MIN_VALUE;
int tempTotal = 0;
for(int i=0;i<nums.length;i++){
tempTotal+=nums[i];
res = Math.max(res,tempTotal);
// 如果和小于0,就重置为0
if(tempTotal<0) tempTotal = 0;
}
return res;
}
}