Skip to content

Commit 04ff946

Browse files
authored
Update string-matching-in-an-array.cpp
1 parent 1737824 commit 04ff946

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

C++/string-matching-in-an-array.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ class Solution2 {
145145

146146
private:
147147
int kmp(const string& text, const string& pattern, const vector<int>& prefix) {
148+
if (pattern.empty()) {
149+
return 0;
150+
}
151+
if (text.length() < pattern.length()) {
152+
return -1;
153+
}
148154
int j = -1;
149155
for (int i = 0; i < text.length(); ++i) {
150156
while (j != -1 && pattern[j + 1] != text[i]) {

0 commit comments

Comments
 (0)