Skip to content

Instantly share code, notes, and snippets.

@thmain
Created February 23, 2016 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/2f59417d7f590ad98c51 to your computer and use it in GitHub Desktop.
Save thmain/2f59417d7f590ad98c51 to your computer and use it in GitHub Desktop.
public class IntersecionPoint2Arrays {
int intersectionPoint = -1;
int x;
int y;
public int intersection(int[] arrA, int[] arrB) {
while (x < arrA.length && y < arrB.length) {
if (arrA[x] > arrB[y])
y++;
else if (arrA[x] < arrB[y])
x++;
else {
intersectionPoint = arrA[x];
return intersectionPoint;
}
}
return intersectionPoint;
}
public static void main(String[] args) throws java.lang.Exception {
int[] a = { 1, 2, 3, 6, 8, 10 };
int[] b = { 4, 5, 6, 11, 15, 20 };
IntersecionPoint2Arrays i = new IntersecionPoint2Arrays();
System.out.println("Intersection point is : " + i.intersection(a, b));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment