static int maxSubArray2(int array[], int size)
{
int maxsofar = 0;
int currentmax = 0;
for (int i = 0; i < size; i++)
{
currentmax = (currentmax + array[i] > 0) ? currentmax + array[i]
: 0;
maxsofar = (maxsofar > currentmax) ? maxsofar : currentmax;
}
return maxsofar;
}
No comments:
Post a Comment