Created
March 29, 2024 15:08
-
-
Save codertcet111/986d6e5883acb4d61073b0713fb80d23 to your computer and use it in GitHub Desktop.
Leetcode 1: two sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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