## [面试题]如何快速的判断两个数组是否有交集

```public boolean hasIntersection(String[] array1, String[] array2)
{
...
}```

array1中，只要有一个在array2中，存在，就返回true，否则返回false

0

hashmap

0
arr2 join 使用特定字符成字符串，然后遍历arr1，在字符串中找arr1的元素。
arr1[0] = "a,b"; arr2[0] = "a"; arr2[1] = "b"; 这种情况下不行
0

0

0

#### 引用来自“God20134”的评论

d

0

0
d

0
d
```public static boolean checkArrayIntercetion(String[] array1,String[] array2){
Map<String,String> map=new HashMap<String,String>();
String[] smallArray=array1.length>array2.length? array2:array1;
String[] bigArray=array1.length> array2.length? array1:array2;
int count=smallArray.length;
for(String s:smallArray){
map.put(s,s);
}
for(String s:bigArray){
map.put(s,s);
count+=1;
if(count%100==0 && count>map.size()){
return true;
}
}
return count>map.size();
}```

0
d

```public static boolean checkArrayIntercetion(String[] array1,String[] array2){
Map<String,String> map1=new HashMap<String,String>();
Map<String,String> map2=new HashMap<String,String>();
String[] smallArray=array1.length>array2.length? array2:array1;
String[] bigArray=array1.length> array2.length? array1:array2;
for(String s:smallArray){
map1.put(s,s);
}
int count=map1.size();
for(String s:bigArray){
map2.put(s,s);
}
for(String key:map2.keySet()){
map1.put(key,key);
count+=1;
if(count%100==0 && count>map.size()){
return true;
}
}
return count>map.size();
}```

count%100==0 && count>map.size() 什么意思？ 整个代码的思路是什么？
0