由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 这两种写法面試时候你喜欢哪种?
相关主题
Check if the sum of two integers in an integer array eqauls to the given number python大牛请进有问题求教
Java: use a HashSet to find the elements that are common in all lists第一次面试几个.NET Web码工
能有人详细讲一下这两道google的面试题吗?为什么不用php + oracle?
算法问题javascript的一个问题:不能用loop,不能用library,怎么来remov (转载)
终于知道了 ++i 比 i++快计算围棋棋盘合法图案的源代码
如何用C++找到三组数据的交集js Q: array[2,0,1,1] => 1102
问高手一个PERL的简单程序nodejs performance
问个基本 C array 问题set operation in c
相关话题的讨论汇总
话题: int话题: set话题: nums2话题: integer话题: nums1
进入Programming版参与讨论
1 (共1页)
C*******n
发帖数: 193
1
349. Intersection of Two Arrays
1
Set set = Arrays.stream(nums2).boxed().collect(Collectors.toSet());
return Arrays.stream(nums1).distinct().filter(e-> set.contains(e)).toArray();
2
public class Solution {
public int[] intersection(int[] nums1, int[] nums2) {
Set set = new HashSet<>();
Set intersect = new HashSet<>();
for (int i = 0; i < nums1.length; i++) {
set.add(nums1[i]);
}
for (int i = 0; i < nums2.length; i++) {
if (set.contains(nums2[i])) {
intersect.add(nums2[i]);
}
}
int[] result = new int[intersect.size()];
int i = 0;
for (Integer num : intersect) {
result[i++] = num;
}
return result;
}
}
1 (共1页)
进入Programming版参与讨论
相关主题
set operation in c终于知道了 ++i 比 i++快
[转载] CS Algorithm Interview question如何用C++找到三组数据的交集
讨论几个面试题问高手一个PERL的简单程序
If using C++, please avoid the use of STL for these questio (转载)问个基本 C array 问题
Check if the sum of two integers in an integer array eqauls to the given number python大牛请进有问题求教
Java: use a HashSet to find the elements that are common in all lists第一次面试几个.NET Web码工
能有人详细讲一下这两道google的面试题吗?为什么不用php + oracle?
算法问题javascript的一个问题:不能用loop,不能用library,怎么来remov (转载)
相关话题的讨论汇总
话题: int话题: set话题: nums2话题: integer话题: nums1