题解 | #连续子数组的最大和#
连续子数组的最大和
http://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484
每次都取比当前数大的和,如果小于当前数,那么就重新计数
public class Solution {
public int FindGreatestSumOfSubArray(int[] array) {
int max=Integer.MIN_VALUE,i,k,l,op=0;
for(int p : array){
op = Math.max(op+p,p);
max = Math.max(op,max);
}
return max;
}
}