不要直接在数组上操作。
public class Solution {
public int FindGreatestSumOfSubArray(int[] array) {
int tmpres = 0,res = Integer.MIN_VALUE;
for (int i = 0; i < array.length; i++) {
if(tmpres>0){
tmpres += array[i];
}else {
tmpres = array[i];
}
res = Math.max(tmpres,res);
}
return res;
}
}

京公网安备 11010502036488号