Simple solution


  • 0
    L
        int maxSubArray(vector<int>& nums) {
            int curr = 0, minsum = 0, maxsum = INT_MIN;
            for (int i = 0; i<nums.size(); ++i){
                curr += nums[i];
                maxsum = max(curr-minsum,maxsum);
                minsum = min(curr,minsum);
            }
        return maxsum;   
        }
    

Log in to reply
 

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