Share my 4ms C solution


  • 0
    Q
    int maxSubArray(int* nums, int numsSize) 
    {
        int* sum = (int*)malloc(sizeof(int) * numsSize);
        sum[0] = nums[0];
        int i, min = 0, d = 0x80000000;
        for(i = 1; i < numsSize; ++i)
            sum[i] = sum[i-1] + nums[i];
        for(i = 0; i < numsSize; ++i)
        {
            if(sum[i] - min > d)
                d = sum[i] - min;
            if(min > sum[i])
                min = sum[i];
        }
        return d;
    }

Log in to reply
 

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