max( dp[ i ] ) = getMax( max( dp[ i -1 ] ) + arr[ i ] ,arr[ i ] )
dp[i]就是以数组下标为i的数做为结尾的最大子序列和
public class Solutrion{
public int FindGreatestSumOfSubArray(int[] array) {
//max就是上面的dp[i]
int max = array[0];
//因为这个dp[i]老是变,所以比如你dp[4]是8 dp[5]就变成-7了,所以需要res保存一下
int res = array[0];
for (int i = 1; i < array.length; i++) {
max = Math.max(max + array[i], array[i]);
res = Math.max(res, max);
}
return res;
}
}