Ruby 4 lines


  • 0
    L
    def two_sum(nums, target)
        map = {}
        (0...nums.length).each do |i|
            return [map[target - nums[i]], i] if map[target - nums[i]]
            map[nums[i]] = i
        end
    end
    

Log in to reply
 

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