Skip to content

Commit 582ff61

Browse files
Merge pull request youngyangyang04#673 from qxuewei/master
添加 349. 两个数组的交集 Swift版本
2 parents 24a7443 + 7447e9a commit 582ff61

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,22 @@ var intersection = function(nums1, nums2) {
192192
};
193193
```
194194

195+
Swift:
196+
```swift
197+
func intersection(_ nums1: [Int], _ nums2: [Int]) -> [Int] {
198+
var set1 = Set<Int>()
199+
var set2 = Set<Int>()
200+
for num in nums1 {
201+
set1.insert(num)
202+
}
203+
for num in nums2 {
204+
if set1.contains(num) {
205+
set2.insert(num)
206+
}
207+
}
208+
return Array(set2)
209+
}
210+
```
195211

196212
## 相关题目
197213

0 commit comments

Comments
 (0)