Created
September 29, 2016 15:00
-
-
Save cjjuice/6a0587ad545f6d9276ce2f22803d0609 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
# @param {Integer[]} nums | |
# @param {Integer} target | |
# @return {Integer[]} | |
def two_sum(nums, target) | |
solution = nil | |
offset = 1 | |
while solution == nil | |
nums.each_with_index do |num, i| | |
if nums[i+offset] && num + nums[i+offset] == target | |
solution = [i, i+offset] | |
end | |
end | |
offset += 1 | |
end | |
return solution | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment