pi static method
Implementation
static int pi(int j, String pattern) {
if (j == 0) return 0;
for (var k = 1; k < pattern.length; k++) {
while (
pattern[j] != pattern[pi(j - 1, pattern)] && pi(j - 1, pattern) > 0) {
return pi(pi(j - 1, pattern) - 1, pattern);
}
if (pattern[j] == pattern[pi(j - 1, pattern)]) {
return pi(j - 1, pattern) + 1;
}
}
return 0;
}