Intersection Of Two ArraysI WayI
严氏北美IT公司面试真题汇总和解答论坛 :: LinkedIn公司面试真题: 注册用户可以看到隐藏题目:2017年下半年上机题,8 9 10三个月的onsite面试真题 :: 求2个list的交集系列题
Page 1 of 1
Intersection Of Two ArraysI WayI
public int[] intersection(int[] nums1, int[] nums2) {
HashSet<Integer> set1 = new HashSet<Integer>();
for(int i: nums1){
set1.add(i);
}
HashSet<Integer> set2 = new HashSet<Integer>();
for(int i: nums2){
if(set1.contains(i)){
set2.add(i);
}
}
int[] result = new int[set2.size()];
int i=0;
for(int n: set2){
result[i++] = n;
}
return result;
}
HashSet<Integer> set1 = new HashSet<Integer>();
for(int i: nums1){
set1.add(i);
}
HashSet<Integer> set2 = new HashSet<Integer>();
for(int i: nums2){
if(set1.contains(i)){
set2.add(i);
}
}
int[] result = new int[set2.size()];
int i=0;
for(int n: set2){
result[i++] = n;
}
return result;
}
Similar topics
» Intersection Of Two ArraysI WayII
» Intersection Of Two ArraysII WayI
» Intersection Of Two ArraysII WayII
» Intersection Of Two ArraysII WayI
» Intersection Of Two ArraysII WayII
严氏北美IT公司面试真题汇总和解答论坛 :: LinkedIn公司面试真题: 注册用户可以看到隐藏题目:2017年下半年上机题,8 9 10三个月的onsite面试真题 :: 求2个list的交集系列题
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum