返回数组中的最大子数组(相邻元素)
//package com.nowjava;/* 来 自 nowjava - 时代Java*/ import java.util.Arrays; public class Main { /** * A famous problem that returns the maximum subarray (contiguous elements) * in an array * - solved using Kadane's algorithm * @param list * @return */ public static Integer[] maxSubarray(Integer[] list) { int maxSoFar = 0; int maxToHere = 0; int l = 0; int r = 0; int temp = 0; for (int a = 0; a < list.length; a++) { if (maxToHere < 0) { /** NowJava.com **/ maxToHere = list[a]; temp = a; } else { maxToHere += list[a]; } if (maxToHere >= maxSoFar) { maxSoFar = maxToHere; l = temp; r =