题解 | #连续子数组的最大和#
连续子数组的最大和
https://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484
class Solution {
public:
int FindGreatestSumOfSubArray(vector<int> array) {
vector<int>dp(array.size(),0);
dp[0] = array[0];
int m=array[0];
for(int i = 1;i < array.size();i++)
{
dp[i] = max(dp[i-1]+array[i],array[i]);
if(dp[i]>m) m = dp[i];
}
return m;
}
};
浮躁!这个题回来一定二刷!
汤臣倍健公司氛围 388人发布