Created
February 6, 2019 18:08
-
-
Save kkchu791/b535d9eea5d3eef84891b445c1874bcc 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
# nums = [2, 3, 11, 22], target = 9, | |
# Because nums[0] + nums[1] = 2 + 7 = 9, | |
#return [0, 1] | |
def two_sum(nums, target) | |
nums.each do |i| | |
nums.each do |x| | |
if i + x == target && nums.index(i) != nums.index(x) | |
return [nums.index(i), nums.index(x)] | |
end | |
end | |
end | |
end | |
two_sum([2, 7, 11, 22], 9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment