Skip to content

Commit cd4222b

Browse files
authored
fix: KMP algorithm (#2712)
1 parent 2dadbf7 commit cd4222b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

strings/knuth_morris_pratt.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ std::vector<int> getFailureArray(const std::string &pattern) {
5454
* \returns `false` if pattern was not found
5555
*/
5656
bool kmp(const std::string &pattern, const std::string &text) {
57+
if (pattern.empty()) {
58+
return true;
59+
}
60+
5761
int text_length = text.size(), pattern_length = pattern.size();
5862
std::vector<int> failure = getFailureArray(pattern);
5963

0 commit comments

Comments
 (0)