Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: let KMP algorithm return index #2713

Merged
merged 8 commits into from
Sep 1, 2024
4 changes: 4 additions & 0 deletions strings/knuth_morris_pratt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ std::vector<int> getFailureArray(const std::string &pattern) {
* \returns `false` if pattern was not found
*/
bool kmp(const std::string &pattern, const std::string &text) {
if (pattern.empty()) {
return true;
}

int text_length = text.size(), pattern_length = pattern.size();
std::vector<int> failure = getFailureArray(pattern);

Expand Down
Loading