@Test public void testOneIntersection() { int[] a = {3, 2, 1}; int[] b = {4, 3, 5, 6, 7}; Assert.assertEquals(1, IntersectionOfTwoSet.intersectionCount(a, b)); }
public static int intersectionCount(int[] a, int[] b) { ISorter shellSorter = new ShellSorter(); shellSorter.sort(a); shellSorter.sort(b); int cnt = 0; int i = 0, j = 0; for (; i < a.length && j < b.length; ) { if (a[i] < b[j]) i++; else if (a[i] > b[j]) j++; else { i++; j++; cnt++; } } return cnt; }
IntersectionOfTwoSet { public static int intersectionCount(int[] a, int[] b) { ISorter shellSorter = new ShellSorter(); shellSorter.sort(a); shellSorter.sort(b); int cnt = 0; int i = 0, j = 0; for (; i < a.length && j < b.length; ) { if (a[i] < b[j]) i++; else if (a[i] > b[j]) j++; else { i++; j++; cnt++; } } return cnt; } }
IntersectionOfTwoSet { public static int intersectionCount(int[] a, int[] b) { ISorter shellSorter = new ShellSorter(); shellSorter.sort(a); shellSorter.sort(b); int cnt = 0; int i = 0, j = 0; for (; i < a.length && j < b.length; ) { if (a[i] < b[j]) i++; else if (a[i] > b[j]) j++; else { i++; j++; cnt++; } } return cnt; }  }
IntersectionOfTwoSet { public static int intersectionCount(int[] a, int[] b) { ISorter shellSorter = new ShellSorter(); shellSorter.sort(a); shellSorter.sort(b); int cnt = 0; int i = 0, j = 0; for (; i < a.length && j < b.length; ) { if (a[i] < b[j]) i++; else if (a[i] > b[j]) j++; else { i++; j++; cnt++; } } return cnt; }  static int intersectionCount(int[] a, int[] b); }
IntersectionOfTwoSet { public static int intersectionCount(int[] a, int[] b) { ISorter shellSorter = new ShellSorter(); shellSorter.sort(a); shellSorter.sort(b); int cnt = 0; int i = 0, j = 0; for (; i < a.length && j < b.length; ) { if (a[i] < b[j]) i++; else if (a[i] > b[j]) j++; else { i++; j++; cnt++; } } return cnt; }  static int intersectionCount(int[] a, int[] b);  }