leetcode53_最长子序列和
作者:互联网
public int maxSubArray(int[] nums) {
int len = nums.length,ans = nums[0];
int[] dp = new int[len];
dp[0] = nums[0];
for(int i = 1; i < len; i++) {
dp[i] = Math.max(nums[i], nums[i]+dp[i-1]);
ans = Math.max(dp[i], ans);
}
return ans;
}
标签:nums,int,max,leetcode53,len,长子,ans,序列,dp 来源: https://www.cnblogs.com/huangming-zzz/p/15863531.html