max sum subarray

PHOTO EMBED

Wed Mar 17 2021 01:58:37 GMT+0000 (UTC)

Saved by @tilak #c++

int maxSubArray(vector<int>& nums) {
        int maxSum = nums[0], currSum = nums[0];
        
        for(int i=1; i < nums.size(); i++)
        {
            currSum += nums[i];
            if(nums[i] > currSum) currSum = nums[i];
            maxSum = (currSum > maxSum) ? currSum : maxSum;
        }
        return maxSum;
    }
content_copyCOPY