Created
June 11, 2014 18:09
-
-
Save hindenbug/eed09788e7efea62a8b9 to your computer and use it in GitHub Desktop.
TapeEquilibrium
This file contains hidden or 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) | |
| # write your code in Ruby 1.9.3 | |
| rsum = a.inject(:+) | |
| lsum = 0 | |
| res = nil | |
| a.each_with_index do |v, i| | |
| rsum -= v | |
| lsum += v | |
| diff = (lsum - rsum).abs | |
| res = diff if res.nil? || diff < res | |
| end | |
| return res | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment