Created
August 5, 2016 11:53
-
-
Save oakinogundeji/e78eba28d6c8b2791fceb186e7fec15e to your computer and use it in GitHub Desktop.
Solution to the equilibrium index problem
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 soln(A): | |
sumA, prevSum, n = sum(A), 0, len(A) | |
for i in xrange(n): | |
rem = sumA - prevSum - A[i] | |
if prevSum == rem: | |
return i | |
else: | |
prevSum += A[i] | |
return -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment