剑指offer:第31题连续子数组的最大和

来源:互联网 发布:中华万年历软件 编辑:程序博客网 时间:2024/05/16 23:36
public class _Test_31_1{    public int FindGreatestSumOfSubArray(int[] array) {        int max = array[0],tempMax = array[0];        for(int i = 1, len = array.length; i < len; ++i) {            tempMax = tempMax < 0 ? array[i] : tempMax + array[i];            max = max > tempMax ? max : tempMax;        }        return max;    }}
原创粉丝点击