mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
添加 349. 两个数组的交集 Swift版本
This commit is contained in:
@ -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