1
0
Fork 0

Update include.hh

This commit is contained in:
Ariel 2024-01-18 14:34:46 +08:00 committed by GitHub
parent d2207f6446
commit 9df9b5de3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 0 deletions

View File

@ -136,4 +136,14 @@ vector<int> kmp(string s, string t) { // find all t in s
} }
return v; return v;
} }
int period(string s) { // find the length of shortest recurring period
int n = s.length();
auto z = calc_z(s);
for (int i = 1; i <= n / 2; ++i) {
if (n % i == 0 && z[i] == n - i) {
return i;
}
}
return n;
}
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////