Files
C/leetcode/src/53.c
2019-09-26 08:29:31 -07:00

14 lines
340 B
C

int maxcmp(int a, int b) {
return a >= b ? a : b;
}
int maxSubArray(int* nums, int numsSize){
int maxSoFar = nums[0], maxEndingHere = nums[0];
for(int i = 1; i < numsSize; i++) {
maxEndingHere = maxcmp(maxEndingHere + nums[i], nums[i]);
maxSoFar = maxcmp(maxSoFar, maxEndingHere);
}
return maxSoFar;
}