Created
July 20, 2012 20:00
-
-
Save jgarlick/3152886 to your computer and use it in GitHub Desktop.
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 find_pair(array, value) | |
lookup = {} | |
array.each_with_index do |i, index| | |
if i < value | |
search = value - i | |
i2 = lookup[search] | |
if i2 then return [i2, i] else lookup[i] = index end | |
end | |
end | |
return nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment