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

Method getNext

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

Source from the content-addressed store, hash-verified

51public:
52
53 vector<int> getNext(string pat) {
54 vector<int> next (pat.size());
55 next[0] = -1;
56 int i = 0, j = -1;
57 while ( i < pat.size() - 1 ) {
58 if (j == -1 or pat[i] == pat[j]) {
59 i ++ ;
60 j ++ ;
61 next[i] = j;
62 } else {
63 j = next[j];
64 }
65 }
66 return next;
67 }
68
69 int strStr(string haystack, string needle) {
70 if (needle.empty()) return 0;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected