(arr1: string[], set1: Set<string>)
| 26 | } |
| 27 | |
| 28 | const hasIntersection = (arr1: string[], set1: Set<string>) => { |
| 29 | const arr2 = Array.from(set1) |
| 30 | const set = new Set(arr1.length > arr2.length ? arr2 : arr1) |
| 31 | const arr = arr1.length > arr2.length ? arr1 : arr2 |
| 32 | for (const item of arr) { |
| 33 | if (set.has(item)) { |
| 34 | return true // 发现交集 |
| 35 | } |
| 36 | } |
| 37 | return false // 没有交集 |
| 38 | } |