每天一道算法题之两个数组的交集II
两个数组的交集II
题目描述:
给定两个数组nums1,nums2,编写一个函数来计算它们的交集。1
分析:
采用哈希表记录一个数组 nums1 中各个元素出现的次数
再次遍历数组 nums2,将共元素保存进数组中,更新哈希表
代码部分:
public int[] intersect(int[] nums1, int[] nums2) {
if(nums1.length <= 0 || nums2.length <= 0) return ne
原创
2020-07-13 20:05:45 ·
196 阅读 ·
0 评论