publicint[] intersection(int[] nums1,int[] nums2) {if (nums1 ==null|| nums2 ==null||nums1.length==0||nums2.length==0) {returnnewint[0]; }// method 3,sort smaller array, then do binary search in it for every elem in large arrayArrays.sort(nums1);// assum nums1 is shorterHashSet<Integer> hs =newHashSet<>(); for (int i =0; i <nums2.length; i++) {int cur = nums2[i];if(!hs.contains(cur) &&Arrays.binarySearch(nums1, cur) >-1) {hs.add(cur); } }int[] res =newint[hs.size()];int k =0;for (Integer elem : hs) { res[k++] = elem; }return res; }