我试图找到最大连续数组总和(包括负数。)请帮助我找出我错的一个案例。
total=0 , sum= INT_MIN ;//initialisation of total and sum
for(int i=0;i<n;i++) //for array of n
{
total = arr[i] + total;
sum= max(total,sum);
if(total<0)
total=0;
}
cout<<sum;
我试图找到最大连续数组总和(包括负数。)请帮助我找出我错的一个案例。
total=0 , sum= INT_MIN ;//initialisation of total and sum
for(int i=0;i<n;i++) //for array of n
{
total = arr[i] + total;
sum= max(total,sum);
if(total<0)
total=0;
}
cout<<sum;