标签:大连 计算机专业 img item title 技术 负数 div detail
int temp_max = array[0];
int max_num = array[0];
for(int i=1;i<array.size();i++){
temp_max = max(array[i], array[i]+temp_max);
max_num = max(temp_max, max_num);
}
return max_num;
1 if (array.empty()) 2 return 0; 3 if (array.size() == 1) 4 return array[0]; 5 6 int maxSum = array[0]; // 最大连续子序列和 7 int endMaxSum = maxSum; // 当前以该元素结尾的序列最大连续子序列和 8 for(int i = 1; i < array.size(); ++i){ 9 if(endMaxSum>0) 10 endMaxSum += array[i]; 11 else 12 endMaxSum = array[i]; 13 if(endMaxSum > maxSum) 14 maxSum = endMaxSum; 15 } 16 return maxSum;
https://blog.csdn.net/zjwreal/article/details/88608962
标签:大连 计算机专业 img item title 技术 负数 div detail
原文地址:https://www.cnblogs.com/wxwhnu/p/11415928.html