f(i) = max(f(i-1), a(i))
public int maxSum(int[] nums) {
if (nums.length == 0) {
return 0;
}
if (nums.length == 1) {
return nums[0];
}
int sumMinus1 = nums[0];
for (int i=1; i<nums.length; i++) {
sumMinus1 = Math.max(sumMinus1, nums[i]);
}
return sumMinus1;
}
网友评论