Skip to content

Instantly share code, notes, and snippets.

@cjjuice
Created September 29, 2016 15:00
Show Gist options
  • Save cjjuice/6a0587ad545f6d9276ce2f22803d0609 to your computer and use it in GitHub Desktop.
Save cjjuice/6a0587ad545f6d9276ce2f22803d0609 to your computer and use it in GitHub Desktop.
# @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