Created
October 11, 2013 14:13
-
-
Save amitm/6935319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def max_consecutive_sum(nums): | |
max_sum = nums[0] | |
current_sum = 0 | |
for i in nums: | |
current_sum += i | |
if current_sum > max_sum: | |
max_sum = current_sum | |
if current_sum <= 0: | |
current_sum = 0 | |
return max_sum | |
if __name__ == '__main__': | |
print max_consecutive_sum([-1, 5, -1, -2, 20, -50, 4]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment