class Solution {
public:
// Function to return the count of the number of elements in
// the intersection of two arrays.
int NumberofElementsInIntersection(int a[], int b[], int n, int m) {
// Your code goes here
unordered_map<int,int> s,t;
int ans=0;
for(int i=0;i<n;i++)
{
s[a[i]]++;
}
for(int i=0;i<m;i++)
{
t[b[i]]++;
}
for(auto x:s)
{
if(t.count(x.first)>0)
{ans++;}
}
return ans;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter