1 class Solution { 2 public: 3 //动态规划,维护两个变量 local[i+1]=max(array[i],local[i]+array[i+1]) 4 int FindGreatestSumOfSubArray(vector<int> array) { 5 int len=array.size(); 6 if(len==0) return 0; 7 if(len==1) return array[0]; 8 int local=array[0]; 9 int global=array[0]; 10 for(int i=1;i<array.size();i++) 11 { 12 local=max(array[i],array[i]+local);//local>0?local+array[i]:array[i] 13 global=max(local,global); 14 } 15 return global; 16 } 17 };