Skip to content

Instantly share code, notes, and snippets.

@codertcet111
Created March 29, 2024 15:08
Show Gist options
  • Save codertcet111/986d6e5883acb4d61073b0713fb80d23 to your computer and use it in GitHub Desktop.
Save codertcet111/986d6e5883acb4d61073b0713fb80d23 to your computer and use it in GitHub Desktop.
Leetcode 1: two sum
Leetcode 1: two sum
# @param {Integer[]} nums
# @param {Integer} target
# @return {Integer[]}
def two_sum(nums, target)
temp_hash = {}
nums.each_with_index do |i, ind|
return [temp_hash[i], ind] if temp_hash[i]
temp_hash[target - i] = ind
end
return nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment