Skip to content

Commit 537ba5a

Browse files
committed
Add solution for first task
1 parent 5bc6a62 commit 537ba5a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

1/two_sum.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# @param {Integer[]} nums
2+
# @param {Integer} target
3+
# @return {Integer[]}
4+
def two_sum(nums, target)
5+
nums.each_with_index do |n, i|
6+
number = target - n
7+
index = nums[i+1..-1].index(number)
8+
return [i, index+i+1] if index
9+
end
10+
end

0 commit comments

Comments
 (0)