Answers for "maximum subarray(Java) leetcode solution"

0

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;
}
Posted by: Guest on September-14-2021

Browse Popular Code Answers by Language