summaryrefslogtreecommitdiff
path: root/string/kmp.cpp
diff options
context:
space:
mode:
authorMZuenni <michi.zuendorf@gmail.com>2023-01-11 11:15:50 +0100
committerMZuenni <michi.zuendorf@gmail.com>2023-01-11 11:15:50 +0100
commit61cac9c0febbb5440b99e22770d917bf3a63c405 (patch)
tree98b7dc3b77ada4cffe5b81daded5516b941f28ec /string/kmp.cpp
parentfd1f2b36e95c03625297b7b8cba3b1a04a0cc0ed (diff)
dont use .size()
Diffstat (limited to 'string/kmp.cpp')
-rw-r--r--string/kmp.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/string/kmp.cpp b/string/kmp.cpp
index 282019e..12ae3eb 100644
--- a/string/kmp.cpp
+++ b/string/kmp.cpp
@@ -1,8 +1,8 @@
vector<int> kmpPreprocessing(const string& sub) {
- vector<int> b(sub.size() + 1);
+ vector<int> b(sz(sub) + 1);
b[0] = -1;
int i = 0, j = -1;
- while (i < (int)sub.size()) {
+ while (i < sz(sub)) {
while (j >= 0 && sub[i] != sub[j]) j = b[j];
i++; j++;
b[i] = j;
@@ -12,10 +12,10 @@ vector<int> kmpPreprocessing(const string& sub) {
vector<int> kmpSearch(const string& s, const string& sub) {
vector<int> pre = kmpPreprocessing(sub), result;
int i = 0, j = 0;
- while (i < (int)s.size()) {
+ while (i < sz(s)) {
while (j >= 0 && s[i] != sub[j]) j = pre[j];
i++; j++;
- if (j == (int)sub.size()) {
+ if (j == sz(sub)) {
result.push_back(i - j);
j = pre[j];
}}