标签:
1 class Solution { 2 public: 3 int FindGreatestSumOfSubArray(vector<int> array) { 4 int i; 5 int len=array.size(); 6 if(len==0) 7 return 0; 8 int dp[len+1]; 9 memset(dp,0,sizeof(dp)); 10 dp[0]=array[0]; 11 for(i=1;i<len;i++){ 12 if(dp[i-1]<=0) 13 dp[i]=array[i]; 14 else 15 dp[i]=dp[i-1]+array[i]; 16 } 17 int max=-999999; 18 for(i=0;i<len;i++) 19 if(max<dp[i]) 20 max=dp[i]; 21 return max; 22 } 23 };
标签:
原文地址:http://www.cnblogs.com/cancangood/p/4948044.html