One Pass Ruby Code


  • 0
    R
    def two_sum(nums, target)
        hash = {}
        nums.each_with_index do |num, index|
            return [hash[num], index] if hash[num]
            hash[target - num] = index
        end
        raise ArgumentError
    end
    

Log in to reply
 

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