Skip to content

Instantly share code, notes, and snippets.

@winnietong
Last active August 29, 2015 14:14
Show Gist options
  • Save winnietong/29be0154b8f8aa8ef376 to your computer and use it in GitHub Desktop.
Save winnietong/29be0154b8f8aa8ef376 to your computer and use it in GitHub Desktop.
Examples
# https://www.dropbox.com/s/xpfbcnnnkmjvwdv/Screenshot%202015-02-02%2022.02.06.png?dl=0
# Equilibrium problem
array = [-1, 3, -4, 5, 1, -6, 2, 1]
def solution(array):
right = sum(array)
left = 0
before = 0
for index, val in enumerate(array):
left = left + before
right = right - val
if left == right:
return index
before = val
return -1
print solution(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment