面试题:最大连续子数组和

#include 

using namespace std;


int main()
{
    int a[] = {1,-1,3,-7,10,-3,6,-8,1};
    int size = sizeof(a)/sizeof(int);
    int curSum = 0;
    int maxSum = a[0];
    for(int i=0;i a[i]) ? curSum+a[i] : a[i];
        if(curSum>maxSum){
            maxSum = curSum;
        }
    }
    printf("maxSum:%d",maxSum);
}

你可能感兴趣的:(面试题)