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;
}
posted @ 2021-01-20 21:10  RougeBW  阅读(24)  评论(0编辑  收藏  举报