LeetCode 349. 两个数组的交集

题目描述

🔥 349. 两个数组的交集

image-20230307195920366

思路分析

排序+双指针

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
func intersection(nums1 []int, nums2 []int) []int {
	numSet := make(map[int]bool)
	res := make([]int, 0)
	for _, num := range nums1 {
		numSet[num] = true
	}
	for _, num := range nums2 {
		if value := numSet[num]; value {
			res = append(res, num)
			numSet[num] = false
		}
	}
	return res
}

🍏 点击查看 Java 题解

1
write your code here

相似题目

题目 难度 题解
两个数组的交集 II Easy  
三个有序数组的交集 Easy  
本文作者:
本文链接: https://hgnulb.github.io/blog/72990362
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处!