Iteration:
public class Solution { public int maxSubArray(int[] nums) { int start = 0, end = nums.length-1; //return sumSubArray(nums, 0, Integer.MIN_VALUE, start, end); int max = Integer.MIN_VALUE; int sum = 0; while(start <= end){ sum += nums[start]; if(sum <= 0){ max = sum > max? sum:max; start++; sum = 0; } else{ max = sum > max? sum:max; start++; } } return max; } }
时间: 2024-10-24 07:35:32