pumpkin subarray

mail@pastecode.io avatar
unknown
java
2 years ago
347 B
3
Indexable
Never
public int maxSubArray(int[] nums) {
        int curSum = 0;
        int maxSum = nums[0];
        for (int i =0 ; i<nums.length; i++) {
            curSum = curSum + nums[i];
            if(curSum > maxSum)
                maxSum = curSum;
            if(curSum < 0)
                curSum = 0;
        }
        return maxSum;
            
    }