Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7ee623f

Browse files
添加0349.两个数组的交集 Ruby实现
1 parent 199827b commit 7ee623f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎problems/0349.两个数组的交集.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,25 @@ object Solution {
465465
}
466466

467467
```
468+
469+
###Ruby
470+
```ruby
471+
def intersection(nums1, nums2)
472+
hash = {}
473+
result = {}
474+
475+
nums1.each do |num|
476+
hash[num] = 1 if hash[num].nil?
477+
end
478+
479+
nums2.each do |num|
480+
#取nums1和nums2交集
481+
result[num] = 1 if hash[num] != nil
482+
end
483+
484+
return result.keys
485+
end
486+
```
468487
## 相关题目
469488

470489
* [350.两个数组的交集 II](https://leetcode.cn/problems/intersection-of-two-arrays-ii/)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /