Jay Kadane动态规划的思想,也称该方法为 Kadane 算法。
算法的时间复杂度为 O(n),能够在线性时间解决问题。
虽然代码很简短,但还是需要好好理解这个算法的思想。
我还没理解啊,咋回事
注意:对于数组全为负的情况,返回0
static int get(int arr[],int number){
int max = 0;
int temp = 0;
for(int i = 0; i < number; i++)
{
temp += arr[i];
if(temp<0)
temp = 0;
if(temp>max)
max = temp;
}
return max;
}
原博客 -> 最大子序列和问题