Skip to content

Commit f73e809

Browse files
author
Oleksandr Kulkov
authored
i+z[i] < n is not needed since c++11
1 parent 8b99a59 commit f73e809

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/string/z-function.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ Formal definition can be represented in the following elementary $O(n^2)$ implem
3030

3131
```cpp
3232
vector<int> z_function_trivial(string s) {
33-
int n = (int) s.length();
33+
int n = s.size();
3434
vector<int> z(n);
35-
for (int i = 1; i < n; ++i)
36-
while (i + z[i] < n && s[z[i]] == s[i + z[i]])
37-
++z[i];
35+
for (int i = 1; i < n; i++) {
36+
while (s[z[i]] == s[i + z[i]]) {
37+
z[i]++;
38+
}
39+
}
3840
return z;
3941
}
4042
```

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