标签:subarray 题目 vector ble ems lse bar for int
简单DP
class Solution {
public:
int dp[100005];
int maxSubArray(vector<int>& nums) {
if(nums.size()==0)
return 0;
int ans = nums[0];
dp[0]=nums[0];
for(int i=1;i<nums.size();i++)
{
if(dp[i-1]<0)
{
dp[i]=nums[i];
ans=max(ans,dp[i]);
}
else
{
dp[i]=dp[i-1]+nums[i];
ans=max(ans,dp[i]);
}
}
return ans;
}
};
标签:subarray 题目 vector ble ems lse bar for int
原文地址:https://www.cnblogs.com/dacc123/p/11427549.html