O(n) time O(1) space and fast


  • 0
    R

    int maxSum = nums[0];
    int maxEH = nums[0];
    for(int i=1;i<nums.size();i++){
    if(maxEH<nums[i]&&maxEH<0){
    maxEH = nums[i];
    }
    else
    maxEH += nums[i];
    maxSum = max(maxSum,maxEH);
    }
    return maxSum;


Log in to reply
 

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