Skip to content

Commit 8ff6464

Browse files
authored
Update distinct-echo-substrings.cpp
1 parent cb299a1 commit 8ff6464

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

C++/distinct-echo-substrings.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ class Solution {
66
int distinctEchoSubstrings(string text) {
77
unordered_set<string> result;
88
int l = text.length() - 1;
9-
for (int i = 0; i < min(2 * l, int(text.length())); ++i) { // aaaaaaabcdefabcdefabcdef
10-
l = min(l, KMP(text, i, &result));
9+
for (int i = 0; i < l; ++i) { // aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabcdefabcdefabcdef
10+
const auto& substr_len = KMP(text, i, &result);
11+
if (substr_len != numeric_limits<int>::max()) {
12+
l = min(l, i + substr_len);
13+
}
1114
}
1215
return result.size();
1316
}

0 commit comments

Comments
 (0)