Skip to content

Instantly share code, notes, and snippets.

@eugene0707
Created February 7, 2017 18:37
Show Gist options
  • Save eugene0707/fb2beed8bd862defd072c58ce7966fd9 to your computer and use it in GitHub Desktop.
Save eugene0707/fb2beed8bd862defd072c58ce7966fd9 to your computer and use it in GitHub Desktop.
Codility equilibrium index ruby 100 X 100
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