Created
December 8, 2019 13:37
-
-
Save eebasadre20/c968e13b34806fb030159d9f65e14051 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# @param {Integer[]} nums1 | |
# @param {Integer[]} nums2 | |
# @return {Integer[]} | |
def intersect(nums1, nums2) | |
result = [] | |
nums3 = Hash.new(0) | |
nums2.each do | num | | |
nums3[num] += 1 | |
end | |
nums1.each do | num | | |
if nums3.has_key?(num) && nums3[num] >= 1 | |
result.push(num) | |
nums3[num] -= 1 | |
end | |
end | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment