dynamic programming 的一道题。curMax是包括当前元素的subarray的max,
gloMax是当前元素之前的整个array的max
public class Solution {
public int maxSubArray(int[] A) {
if(A.length == 1) {
return A[0];
}
if(A.length == 0) {
return 0;
}
int curMax = A[0];
int gloMax = A[0];
for(int i = 1;i<A.length;i++){
curMax = Math.max(curMax+A[i], A[i]);
gloMax = Math.max(gloMax, curMax);
}
return gloMax;
}
}