Created
February 7, 2017 18:37
-
-
Save eugene0707/fb2beed8bd862defd072c58ce7966fd9 to your computer and use it in GitHub Desktop.
Codility equilibrium index ruby 100 X 100
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 solution(a) | |
l=0 | |
r=a.reduce(0, :+) | |
a.each_with_index do |e, i| | |
r-= e | |
return i if l==r | |
l+=e | |
end | |
-1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment