| 51 | public: |
| 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; |
nothing calls this directly
no outgoing calls
no test coverage detected