标签:
1 class Solution { 2 public: 3 int FindGreatestSumOfSubArray(vector<int> array) { 4 if ((int)array.size() <= 0)//测试异常输入 5 return 0; 6 vector<int> res; 7 res.push_back(array[0]); 8 int max = res[0]; 9 for (int i = 1; i < (int)array.size();i++) 10 { 11 if (res[i - 1] <= 0) 12 res.push_back(array[i]); 13 else 14 res.push_back(res[i-1]+array[i]); 15 16 if (res[i]>max) 17 max = res[i]; 18 } 19 return max; 20 } 21 };
标签:
原文地址:http://www.cnblogs.com/lou424/p/5031074.html