350. Intersection of Two Arrays II

public class Solution {
    public int[] intersect(int[] nums1, int[] nums2) {
        HashMap map=new HashMap<>();
        ArrayList arr=new ArrayList<>();
        for(int i=0;i0){
                arr.add(nums2[i]);
                map.put(nums2[i],map.get(nums2[i])-1);
            }
        }
        int k=0;
        int[] res=new int[arr.size()];
        for(Integer num: arr){
            res[k++]=num;
        }
        return res;
    }
}

你可能感兴趣的:(350. Intersection of Two Arrays II)