mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
@ -192,6 +192,22 @@ var intersection = function(nums1, nums2) {
|
||||
};
|
||||
```
|
||||
|
||||
Swift:
|
||||
```swift
|
||||
func intersection(_ nums1: [Int], _ nums2: [Int]) -> [Int] {
|
||||
var set1 = Set<Int>()
|
||||
var set2 = Set<Int>()
|
||||
for num in nums1 {
|
||||
set1.insert(num)
|
||||
}
|
||||
for num in nums2 {
|
||||
if set1.contains(num) {
|
||||
set2.insert(num)
|
||||
}
|
||||
}
|
||||
return Array(set2)
|
||||
}
|
||||
```
|
||||
|
||||
## 相关题目
|
||||
|
||||
|
Reference in New Issue
Block a user