DEV Community

Discussion on: Daily Challenge #63- Two Sum

Collapse
 
playwright2poli profile image
playwrightpo • Edited

Ruby

The initial solution comes to mind which obviously could be improved in performance purposes having more time

  def two_sum(array, target)
    array.each_with_index do |item, i|
      (i + 1).upto(array.size - 1) do |j|
        return [i, j] if item + array[j] == target
      end
    end

    nil
  end