Ruby Clean & Short


  • 0
    N

    Post this simply because this world needs more Ruby ;)

    def two_sum(nums, target)
      dict = {}
      nums.each_with_index do |n, i|
        if dict[target - n]
          return dict[target - n], i
        end
        dict[n] = i
      end
    end
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.