simple C solution,O(n),3 ms


  • 0
    W
    int maxSubArray(int* nums, int numsSize) {
        int curSum = nums[0],maxSum = nums[0];
        for (int i = 1; i < numsSize; i++) {
            if (curSum <= 0) curSum = nums[i];
            else curSum += nums[i];
            if (curSum > maxSum) maxSum = curSum;
        }
        return maxSum;
    }
    

Log in to reply
 

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