1.简述：

[1,-2,3,10,-4,7,2,-5]

[3,10,-4,7,2]

经分析可知，输入数组的子数组[3,10,-4,7,2]可以求得最大和为18，故返回[3,10,-4,7,2]

[1]

[1]

[1,2,-3,4,-1,1,-3,2]

[1,2,-3,4,-1,1]

经分析可知，最大子数组的和为4，有[4],[4,-1,1],[1,2,-3,4],[1,2,-3,4,-1,1]，故返回其中长度最长的[1,2,-3,4,-1,1]

[-2,-1]

[-1]

子数组最小长度为1，故返回[-1]

2.代码实现：

import java.util.*;public class Solution {    public int[] FindGreatestSumOfSubArray (int[] array) {        int x = array[0];        int y = 0;        int maxsum = x;        //滑动区间        int left = 0, right = 0;         //记录最长的区间        int resl = 0, resr = 0;         for(int i = 1; i < array.length; i++){            right++;            //状态转移：连续子数组和最大值            y = Math.max(x + array[i], array[i]);             //区间新起点            if(x + array[i] < array[i])                 left = right;            //更新最大值            if(y > maxsum || y == maxsum && (right - left + 1) > (resr - resl + 1)){                 maxsum = y;                resl = left;                resr = right;            }            //更新x的状态            x = y;         }        //取数组        int[] res = new int[resr - resl + 1];        for(int i = resl; i <= resr; i++)             res[i - resl] = array[i];        return res;    }}