List<int> FindIntersection(int[] A, int[] B)
{
int L = A.Length;
int K = B.Length;
List<int> intersectionArr = new List<int>();
int i = L - 1;
int j = K - 1;
while ((i >= 0) && (j >= 0))
{
if (A[i] > B[j])
{
i--;
}
else if (B[j] > A[i])
{
j--;
}
else
{
intersectionArr.Add(A[i]);
i--;
j--;
}
}
return intersectionArr;
}
Thursday, May 28, 2015
L Question: Intersection for Two Arrays
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment