20 lines
539 B
C++
20 lines
539 B
C++
#include <bits/stdc++.h>
|
|
#include <math.h>
|
|
#include <algorithm>
|
|
|
|
int maxSubArray(int* nums, int numsSize) {
|
|
int curmax = -1000000;
|
|
int all_max = -1000000;
|
|
for (int i = 0; i < numsSize; i++) {
|
|
curmax = nums[i] > curmax + nums[i] ? nums[i] : curmax + nums[i];
|
|
all_max = all_max > curmax ? all_max : curmax;
|
|
// printf("%d %d\n", curmax, all_max);
|
|
}
|
|
return all_max;
|
|
}
|
|
|
|
int main() {
|
|
int nums[] = {-3, -2, -2, -3};
|
|
printf("%d\n", maxSubArray(nums, sizeof(nums) / sizeof(int)));
|
|
return 0;
|
|
} |