题解 | #连续子数组的最大和#
连续子数组的最大和
https://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484
class Solution { public: int FindGreatestSumOfSubArray(vector<int> array) { int ans=array[0],max=array[0]; for(int i=1;i<array.size();i++){ if(ans>0){ ans+=array[i]; max=ans>max?ans:max; } else { ans=array[i]; max=ans>max?ans:max; } } return max; } };