Last active
August 29, 2015 14:14
-
-
Save winnietong/29be0154b8f8aa8ef376 to your computer and use it in GitHub Desktop.
Examples
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
# 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