Skip to content

Commit 3559d67

Browse files
committed
🟢 Solve problem 350
1 parent c9e5d0d commit 3559d67

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎swift/350.swift

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
func intersect(_ nums1: [Int], _ nums2: [Int]) -> [Int] {
3+
var countMap = [Int: Int]()
4+
var intersection = [Int]()
5+
6+
for value1 in nums1 {
7+
countMap[value1, default: 0] += 1
8+
}
9+
10+
for value2 in nums2 {
11+
if let count = countMap[value2], count > 0 {
12+
intersection.append(value2)
13+
countMap[value2] = count - 1
14+
}
15+
}
16+
17+
return intersection
18+
}
19+
}

0 commit comments

Comments
 (0)