https://blog.youkuaiyun.com/wangaohan0728/article/details/88094581
bool maxSub(int a[],int len,int*ret) {
if (a == NULL || 0 == len) {
return false;
}
int total=0;
int curTotal=0;
for (int i = 0; i<len-1; i++) {
if (curTotal + a[i] >=0) {
curTotal = curTotal + a[i];
if (curTotal >=total) {
total = curTotal;
}
}
else {
curTotal = 0;
}
}
*ret = total;
return true;
}
int maxsub[] = {1, -2, 3, 10, -4, 7, 2, -5};
int maxSubRet;
maxSub(maxsub, 8, &maxSubRet);