Skip to content

Commit 3607b18

Browse files
committed
leetcode
1 parent 985bb9a commit 3607b18

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
11
package main
2+
3+
import "sort"
4+
5+
func intersect(nums1 []int, nums2 []int) []int {
6+
sort.Ints(nums1)
7+
sort.Ints(nums2)
8+
var result []int
9+
var left int = 0
10+
var right int = 0
11+
for left < len(nums1) && right < len(nums2) {
12+
if nums1[left] == nums2[right] {
13+
result = append(result, nums1[left])
14+
left++
15+
right++
16+
} else if nums1[left] < nums2[right] {
17+
left++
18+
} else {
19+
right++
20+
}
21+
}
22+
return result
23+
}

0 commit comments

Comments
 (0)