@Test public void basicTest() { assertEquals(2, TandemRepeat.solve("abcab", "abcabcababcaba")); assertEquals(3, TandemRepeat.solve("abcab", "abcababcababcab")); assertEquals(0, TandemRepeat.solve("abcab", "b")); assertEquals(0, TandemRepeat.solve("abcab", "abcbab")); assertEquals(-1, TandemRepeat.solve("", "b")); }
public static int solve(String pattern, String text) { int m = text.length(); int n = pattern.length(); if (n == 0) return -1; int k = m / n; if (k == 0) return 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < k; i++) { sb.append(pattern); } MyKMP kmp = new KMPplus(sb.toString()); kmp.search(text); return kmp.getMaxJ() / n; }
TandemRepeat { public static int solve(String pattern, String text) { int m = text.length(); int n = pattern.length(); if (n == 0) return -1; int k = m / n; if (k == 0) return 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < k; i++) { sb.append(pattern); } MyKMP kmp = new KMPplus(sb.toString()); kmp.search(text); return kmp.getMaxJ() / n; } }
TandemRepeat { public static int solve(String pattern, String text) { int m = text.length(); int n = pattern.length(); if (n == 0) return -1; int k = m / n; if (k == 0) return 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < k; i++) { sb.append(pattern); } MyKMP kmp = new KMPplus(sb.toString()); kmp.search(text); return kmp.getMaxJ() / n; }  }
TandemRepeat { public static int solve(String pattern, String text) { int m = text.length(); int n = pattern.length(); if (n == 0) return -1; int k = m / n; if (k == 0) return 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < k; i++) { sb.append(pattern); } MyKMP kmp = new KMPplus(sb.toString()); kmp.search(text); return kmp.getMaxJ() / n; }  static int solve(String pattern, String text); }
TandemRepeat { public static int solve(String pattern, String text) { int m = text.length(); int n = pattern.length(); if (n == 0) return -1; int k = m / n; if (k == 0) return 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < k; i++) { sb.append(pattern); } MyKMP kmp = new KMPplus(sb.toString()); kmp.search(text); return kmp.getMaxJ() / n; }  static int solve(String pattern, String text);  }