Skip to content

Instantly share code, notes, and snippets.

@hahastudio
Created August 19, 2021 10:35
Show Gist options
  • Save hahastudio/ec6c851a67c714ac40cf406a2aeeb525 to your computer and use it in GitHub Desktop.
Save hahastudio/ec6c851a67c714ac40cf406a2aeeb525 to your computer and use it in GitHub Desktop.
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