添加0349.两个数组的交集 Ruby实现
This commit is contained in:
parent
199827b6c2
commit
7ee623f4da
|
|
@ -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/)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue