求整数数组中连续子序列之和最大值,其中整数数组可以为正数、负数、0
整数数组
连续子序列之和最大值
-2,4,-2,7,-6,-1
9
import java.util.*; public class Main { public int solution(int[] input, int n) { int maxSum = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { int sum = 0; for (int j = i; j < n; j++) { sum += input[j]; if (sum > maxSum) { maxSum = sum; } } } return maxSum; } }