Skip to content

Commit c4428ce

Browse files
committed
fix z_function
1 parent e291a7e commit c4428ce

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/string/z-function.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ vector<int> z_function_trivial(string s) {
3333
int n = s.size();
3434
vector<int> z(n);
3535
for (int i = 1; i < n; i++) {
36-
while (s[z[i]] == s[i + z[i]]) {
36+
while (i + z[i] < n && s[z[i]] == s[i + z[i]]) {
3737
z[i]++;
3838
}
3939
}
@@ -96,7 +96,7 @@ vector<int> z_function(string s) {
9696
if(i < r) {
9797
z[i] = min(r - i, z[i - l]);
9898
}
99-
while(s[z[i]] == s[i + z[i]]) {
99+
while(i + z[i] < n && s[z[i]] == s[i + z[i]]) {
100100
z[i]++;
101101
}
102102
if(i + z[i] > r) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy