Created
August 19, 2021 10:35
-
-
Save hahastudio/ec6c851a67c714ac40cf406a2aeeb525 to your computer and use it in GitHub Desktop.
gist for https://www.v2ex.com/t/796730
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 continuous_sum(lst): | |
if len(lst) <= 1: | |
return lst | |
total = 0 | |
results = [] | |
for i in lst: | |
if i == 0: | |
continue | |
if i > 0: | |
if total >= 0: | |
total += i | |
else: | |
results.append(total) | |
total = i | |
if i < 0: | |
if total <= 0: | |
total += i | |
else: | |
results.append(total) | |
total = i | |
results.append(total) | |
return results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment