Content deleted Content added
Tags: Reverted Visual edit |
Undid revision 1165247576 by AsiansNextDoor (talk) No no no. This is by far the most frequent edit and the most frequent wrong edit on this article. How many comments do we have to put in to head off more of the same mistake? Note the line immediately above: "This version of the algorithm will return 0 if the input contains no positive elements (including when the input is empty)." |
||
Line 62:
Thus, the problem can be solved with the following code,{{sfn|Bentley|1989|p=74}}{{sfn|Gries|1982|p=211}} expressed below in [[Python (programming language)|Python]]. This version of the algorithm will return 0 if the input contains no positive elements (including when the input is empty).
<syntaxhighlight lang="python" line
def max_subarray(numbers):
best_sum = 0
current_sum = 0
for x in numbers:
current_sum = max(
best_sum = max(best_sum, current_sum)
return best_sum
|