Skip to content

Instantly share code, notes, and snippets.

@shdown
Created April 19, 2020 00:27
Show Gist options
  • Save shdown/45c201fae4e019c7b179fc254127a046 to your computer and use it in GitHub Desktop.
Save shdown/45c201fae4e019c7b179fc254127a046 to your computer and use it in GitHub Desktop.
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