-
-
Save shdown/45c201fae4e019c7b179fc254127a046 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size_t l = 0, r = 0; | |
for (size_t i = 1; i < n; ++i) { | |
size_t val = 0; | |
if (i < r) | |
val = min(r - i, z[i - l]); | |
while (i + val < n && s[val] == s[i + val]) | |
++val; | |
z[i] = val; | |
if (r < i + val) { | |
r = i + val; | |
l = i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment