Easy to Understand || HashMap || HashSet || O(n+m) O(n+m)
Code1: HashSet\n\n# Approach\n Describe your approach to solving the problem. \n Maintain the 2 Set/HashMap (hm1,hm2) for array nums1 and nums2\n Check if eleme
# Code1: HashSet\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* Maintain the 2 Set/HashMap (hm1,hm2) for array nums1 and nums2\n* Check if elements of nums1 present in hm2 then maintain counter (a) \n* Similarly check if elements of nums2 in hm1 then main counter (b)\n\n# Complexity\n- Time complexity: O(n+m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n+m)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int[] findIntersectionValues(int[] nums1, int[] nums2) {\n        HashSet<Integer> hm1 = new HashSet<>();\n        for(int i=0;i<nums1.length;i++){\n            hm1.add(nums1[i]);\n        }\n\n        HashSet<Integer> hm2 = new HashSet<>();\n        for(int i=0;i<nums2.length;i++){\n            hm2.add(nums2[i]);\n        }\n\n        int a = 0;\n        for(int i=0;i<nums1.length;i++){\n            if(hm2.contains(nums1[i])){\n                a++;\n            }\n        }\n\n        int b = 0;\n        for(int i=0;i<nums2.length;i++){\n            if(hm1.contains(nums2[i])){\n                b++;\n            }\n        }\n\n        int[] ans=  new int[2];\n        ans[0] = a;\n        ans[1] = b;\n        return ans;\n    }\n}\n```\n # Code 2: HashMap:\n\n# Complexity\n- Time complexity: O(n+m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n+m)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n```\nclass Solution {\n    public int[] findIntersectionValues(int[] nums1, int[] nums2) {\n        HashMap<Integer, Integer> hm1 = new HashMap<>();\n        for(int i=0;i<nums1.length;i++){\n            hm1.put(nums1[i], hm1.getOrDefault(nums1[i],0)+1);\n        }\n\n        HashMap<Integer, Integer> hm2 = new HashMap<>();\n        for(int i=0;i<nums2.length;i++){\n            hm2.put(nums2[i], hm2.getOrDefault(nums2[i],0)+1);\n        }\n\n        int a = 0;\n        for(int i=0;i<nums1.length;i++){\n            if(hm2.containsKey(nums1[i])){\n                a++;\n            }\n        }\n\n        int b = 0;\n        for(int i=0;i<nums2.length;i++){\n            if(hm1.containsKey(nums2[i])){\n                b++;\n            }\n        }\n\n        int[] ans=  new int[2];\n        ans[0] = a;\n        ans[1] = b;\n        return ans;\n    }\n}\n```\n
['Array', 'Hash Table', 'Java']