Skip to content

Commit 8cf259a

Browse files
authored
Update length-of-the-longest-valid-substring.cpp
1 parent d41a433 commit 8cf259a

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

C++/length-of-the-longest-valid-substring.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ class Solution {
99
for (const auto& w : forbidden) {
1010
trie.insert(w);
1111
}
12-
const int l = size(*max_element(cbegin(forbidden), cend(forbidden), [](const auto& a, const auto& b) {
13-
return size(a) < size(b);
14-
}));
1512
int result = 0;
1613
for (int left = size(word) - 1, right = size(word) - 1; left >= 0; --left) {
17-
for (int i = left, curr = 0; i < min(right + 1, left + l); ++i) {
14+
for (int i = left, curr = 0; i <= right; ++i) {
1815
curr = trie.child(curr, word[i]);
19-
if (!curr) {
16+
if (!curr) { // O(l) times
2017
break;
2118
}
2219
if (trie.is_string(curr)) {

0 commit comments

Comments
 (0)