1齿诉、前言
2拒炎、思路
動(dòng)態(tài)規(guī)劃
3祖今、代碼
class Solution {
public int maximumSum(int[] arr) {
int dp0 = arr[0], dp1 = 0, res = arr[0];
for(int i = 1; i < arr.length; i++){
dp1 = Math.max(dp0, dp1 + arr[i]);
dp0 = Math.max(dp0, 0) + arr[i];
res = Math.max(res, Math.max(dp0, dp1));
}
return res;
}
}