1.链接
53. 最大子数组和 - 力扣(LeetCode)
2.描述
3.思路
4.参考代码
class Solution {
public:
int maxSubArray(vector<int>& nums)
{
int n = nums.size();
vector<int> dp(n+1,0);
int ret = INT_MIN;
for(int i = 1;i<=n;i++)
{
dp[i] = max(dp[i-1]+nums[i-1],nums[i-1]);
ret = max(ret,dp[i]);
}
return ret;
}
};