Fix for max subarray sum

This commit is contained in:
Nikita Zhiltsov 2019-11-17 16:15:07 -08:00
parent f269ae3919
commit 2755a634d8
1 changed files with 2 additions and 2 deletions

View File

@ -487,8 +487,8 @@ for each ending position from left to right.
The following code implements the algorithm:
\begin{lstlisting}
int best = 0, sum = 0;
for (int k = 0; k < n; k++) {
int best = array[0], sum = array[0];
for (int k = 1; k < n; k++) {
sum = max(array[k],sum+array[k]);
best = max(best,sum);
}