Topic link: LeeCode53 maximum sub-sequence and
topic description:
simple dp, when recording to the current position, judge the previously recorded maximum sub-sequence sum and the maximum sub-sequence sum added to the current position, the maximum value is the maximum sub-sequence sum
class Solution {
public static int maxSubArray(int[] nums) {
int[] dp=new int[nums.length];
int max=nums[0];
dp[0]=nums[0];
for (int i = 1; i < nums.length; i++) {
dp[i]= Math.max(nums[i],nums[i]+dp[i-1] );
max= Math.max(max,dp[i]);
}
return max;
}
}