diff options
Diffstat (limited to 'spec/leetcode/1_two_sum_spec.rb')
| -rw-r--r-- | spec/leetcode/1_two_sum_spec.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/spec/leetcode/1_two_sum_spec.rb b/spec/leetcode/1_two_sum_spec.rb index 739d0e0..1c238ff 100644 --- a/spec/leetcode/1_two_sum_spec.rb +++ b/spec/leetcode/1_two_sum_spec.rb @@ -8,12 +8,12 @@ describe description do def two_sum(numbers, target:) items = {} numbers.each_with_index do |number, index| - next if number > target if other_index = items[target - number] return [index, other_index].sort end items[number] = index end + [] end it 'returns 2 + 7' do @@ -27,4 +27,10 @@ describe description do results = two_sum(numbers, target: 6) expect(results).to eql([1, 2]) end + + it 'returns -3 + 3' do + numbers = [-3, 4, 3, 90] + results = two_sum(numbers, target: 0) + expect(results).to eql([0, 2]) + end end |
