Content deleted Content added
Tags: Reverted Visual edit |
Undid revision 1174756409 by 92.40.215.21 (talk) |
||
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):
"""Find the largest sum of any contiguous subarray."""
Line 68:
current_sum = 0
for x in numbers:
current_sum = max(
best_sum = max(best_sum, current_sum)
return best_sum
|