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