Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

maximum subarray(Java) leetcode solution

public int maxSubArray(int[] nums) {
    int result = nums[0];
    int sum = nums[0];
 
    for(int i=1; i<nums.length; i++){
        sum = Math.max(nums[i], sum + nums[i]);
        result = Math.max(result, sum);
    }
 
    return result;
}
Source by www.programcreek.com #
 
PREVIOUS NEXT
Tagged: #maximum #leetcode #solution
ADD COMMENT
Topic
Name
2+6 =