Skip to content

Instantly share code, notes, and snippets.

@axiaoxin
Created February 10, 2014 05:01
Show Gist options
  • Save axiaoxin/8910630 to your computer and use it in GitHub Desktop.
Save axiaoxin/8910630 to your computer and use it in GitHub Desktop.
def find_zero_sum(arr):
sums = [0] * len(arr)
for i, x in enumerate(arr):
for j in range(0, i + 1):
sums[j] += arr[i]
if sums[j] == 0:
return (j, i)
arr = [8, 1, 2, 7, -4, -6]
zero_sum_index = find_zero_sum(arr)
assert zero_sum_index == (1, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment