MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / strStr

Method strStr

28. Implement strStr()/Solution.cpp:34–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32 }
33
34 int strStr(string haystack, string needle) {
35 if (needle.empty()) return 0;
36 if (haystack.empty()) return -1;
37 this->pat = needle;
38 this->init();
39 string txt = haystack;
40 int state = 0, found = needle.size();
41 for (int i = 0; i < txt.size(); i ++ ) {
42 state = this->dfa[state][haystack.at(i)];
43 if (state == found) return i - needle.size() + 1;
44 }
45 return -1;
46 }
47};
48
49// kmp next version

Callers

nothing calls this directly

Calls 2

initMethod · 0.95
emptyMethod · 0.80

Tested by

no test coverage detected