mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
添加0349.两个数组的交集 Ruby实现
This commit is contained in:
@ -465,6 +465,25 @@ object Solution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
###Ruby
|
||||||
|
```ruby
|
||||||
|
def intersection(nums1, nums2)
|
||||||
|
hash = {}
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
nums1.each do |num|
|
||||||
|
hash[num] = 1 if hash[num].nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
nums2.each do |num|
|
||||||
|
#取nums1和nums2交集
|
||||||
|
result[num] = 1 if hash[num] != nil
|
||||||
|
end
|
||||||
|
|
||||||
|
return result.keys
|
||||||
|
end
|
||||||
|
```
|
||||||
## 相关题目
|
## 相关题目
|
||||||
|
|
||||||
* [350.两个数组的交集 II](https://leetcode.cn/problems/intersection-of-two-arrays-ii/)
|
* [350.两个数组的交集 II](https://leetcode.cn/problems/intersection-of-two-arrays-ii/)
|
||||||
|
Reference in New Issue
Block a user