leetcode-剑指42-OK
同leetcode的53
address
int maxSubArray(int* nums, int numsSize){
int sum[numsSize];
sum[0] = nums[0];
for(int i = 1; i<numsSize; i++){
sum[i] = sum[i-1] +nums[i];
}
int min = 0,answer = sum[0];
for(int i = 0; i<numsSize; i++){
if(sum[i]-min > answer)
answer = sum[i]-min;
if(sum[i]<min)
min = sum[i];
}
return answer;
}