public class Solution {
public int FindGreatestSumOfSubArray(int[] array) {
//设置指针从0开始向右移动,如果当前指针 + 前面指针代表的和为sum,计算max
//如果sum > 0 移动 sum = sum
//如果素sum < 0 移动 sum归零 重写跳转指针
if(array == null){
return 0;
}
int i = 0;
int max = Integer.MIN_VALUE;
int sum = 0;
while(i < array.length){
sum = array[i] + sum;
max = max > sum ? max : sum;
if(sum < 0){
sum = 0;
}
i++;
}
return max;
}
}