100% Beat💪 || C++ || Java  || Easy to Understand🫶
Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to find the count of common elements between two given arrays (nums1 and nu
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to find the count of common elements between two given arrays (nums1 and nums2). To achieve this, we can use sets to efficiently check for common elements.\n\n\n---\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Create sets (set1 and set2) from the input arrays nums1 and nums2 to remove duplicates.\n2. Initialize counters (count1 and count2) to 0 to keep track of common elements.\n3. Iterate through each element of nums1 and check if it exists in set2. If it does, increment count1.\n4. Iterate through each element of nums2 and check if it exists in set1. If it does, increment count2.\n5. Return the counts of common elements in the form of a vector {count1, count2}.\n\n---\n\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\n---\n\n\n# **Please Upvote \uD83D\uDE4F\uD83C\uDFFB**\n\n---\n\n\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    std::vector<int> findIntersectionValues(std::vector<int>& nums1, std::vector<int>& nums2) {\n        std::set<int> set1(nums1.begin(), nums1.end());\n        std::set<int> set2(nums2.begin(), nums2.end());\n\n        int count1 = 0;\n        for (int num : nums1) {\n            if (set2.count(num)) {\n                count1++;\n            }\n        }\n\n        int count2 = 0;\n        for (int num : nums2) {\n            if (set1.count(num)) {\n                count2++;\n            }\n        }\n\n        return {count1, count2};\n    }\n};\n```\n```java []\npublic class Solution {\n    public int[] findIntersectionValues(int[] nums1, int[] nums2) {\n        Set<Integer> set1 = new HashSet<>();\n        Set<Integer> set2 = new HashSet<>();\n\n        for (int num : nums1) {\n            set1.add(num);\n        }\n\n        for (int num : nums2) {\n            set2.add(num);\n        }\n\n        int count1 = 0;\n        for (int num : nums1) {\n            if (set2.contains(num)) {\n                count1++;\n            }\n        }\n\n        int count2 = 0;\n        for (int num : nums2) {\n            if (set1.contains(num)) {\n                count2++;\n            }\n        }\n\n        return new int[]{count1, count2};\n    }\n}\n\n```
['C++', 'Java']