12 line c solution.


  • 0
    A

    int maxSubArray(int* nums, int numsSize) {

    int prev = nums[0], max = prev;
    for (int i=1 ; i < numsSize; i++) {
        if(prev > 0) {
            prev += nums[i];
        }else {
            prev = nums[i];
        }
        if (prev > max) {
            max = prev;
        }
    }
    return max;
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.