MCPcopy Create free account
hub / github.com/Seogeurim/CS-study / kmp

Method kmp

contents/algorithm/code/KMPTest.java:33–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31 }
32
33 static int kmp() {
34 int count = 0;
35 for (int i = 0, j = 0; i < T.length(); i++) {
36 while (j > 0 && T.charAt(i) != P.charAt(j))
37 j = fail[j-1];
38 if (T.charAt(i) == P.charAt(j)) {
39 if (j == N-1) { // 끝까지 왔음
40 j = fail[j];
41 count ++;
42 match_index.append(i-N+2).append("\n");
43 } else {
44 j ++;
45 }
46 }
47 }
48 return count;
49 }
50}

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected