349. Intersection of Two Arrays

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了349. Intersection of Two Arrays相关的知识,希望对你有一定的参考价值。

https://leetcode.com/problems/intersection-of-two-arrays/#/solutions

http://www.cnblogs.com/EdwardLiu/p/6096747.html

三种方法哦哦哦

public int[] intersection(int[] nums1, int[] nums2) {
Set<Integer> ans = new HashSet<>();
Set<Integer> set = new HashSet<>();
for (int num : nums1) {
set.add(num);
}
for (int num : nums2) {
if (set.contains(num)) {
ans.add(num);
}
}
int[] res = new int[ans.size()];
int i = 0;
for (Integer num : ans) {
res[i++] = num;
}
return res;
}

技术分享

 


















以上是关于349. Intersection of Two Arrays的主要内容,如果未能解决你的问题,请参考以下文章

349. Intersection of Two Arrays

349. Intersection of Two Arrays

Leetcode 349. Intersection of Two Arrays

[leetcode]349.Intersection of Two Arrays

349. Intersection of Two Arrays

Leetcode-349 Intersection of Two Arrays