Skip to content

Commit

Permalink
167
Browse files Browse the repository at this point in the history
  • Loading branch information
TedTran2019 committed Jul 8, 2022
1 parent 9ad3ada commit bd52434
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ruby/167-Two-Sum-II.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def two_sum(numbers, target)
idx_start = 0
idx_end = numbers.length - 1
while idx_start < idx_end
case numbers[idx_start] + numbers[idx_end] <=> target
when 1
idx_end -= 1
when 0
return [idx_start + 1, idx_end + 1]
when -1
idx_start += 1
end
end
nil
end

0 comments on commit bd52434

Please sign in to comment.