Skip to content

Commit

Permalink
Create arrayintersection.cpp
Browse files Browse the repository at this point in the history
anmolrishi#13 
array intersection in cpp
  • Loading branch information
mhdshameel authored Oct 27, 2018
1 parent d47883e commit 4f821e0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Intersection of two Integer arrays/arrayintersection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <vector>

//approach with O(n2) time complexity
std::vector<int> ArrayIntersections(int * arr1, int arr1_size, int * arr2, int arr2_size)
{
std::vector<int> vIntersections;
for(int i = 0; i<arr1_size; i++)
{
for(int j = 0; i<arr2_size; i++)
{
if(arr1[i] ^ arr2[j])
{
continue;
}
else
{
//both are equal
vIntersections.push_back(arr1[i]);
break;
}
}
}
return vIntersections;
}

0 comments on commit 4f821e0

Please sign in to comment.