Skip to content

Commit bd82f56

Browse files
author
laileon
committed
refactor
1 parent c71ba77 commit bd82f56

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/com/blankj/csutom/KMP.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.blankj.csutom;
22

3+
import java.util.Arrays;
4+
35
public class KMP {
46
// http://blog.csdn.net/v_july_v/article/details/7041827
57
// http://blog.csdn.net/christ1750/article/details/51259425
@@ -13,6 +15,7 @@ public class KMP {
1315
// 失配时,模式串向右移动的位数为:失配字符所在位置 - 失配字符对应的next 值
1416

1517
public static int[] kmpnext(String dest) {
18+
// String a = "baba"; [0,0,1,2]
1619
int[] next = new int[dest.length()];
1720
next[0] = 0;
1821
for (int i = 1, j = 0; i < dest.length(); i++) {
@@ -43,15 +46,12 @@ public static int kmp(String str, String dest, int[] next) {//str文本串 dest
4346
}
4447

4548
public static void main(String[] args) {
46-
String a = "baba";
47-
String b = "ssdfgasdbababa";
49+
String a = "abcabe";
50+
String b = "abcabcabea";
4851
int[] next = kmpnext(a);
4952
int res = kmp(b, a, next);
50-
51-
System.out.println(res);
52-
for (int i = 0; i < next.length; i++) {
53-
System.out.println(next[i]);
54-
}
55-
System.out.println(next.length);
53+
54+
System.out.println("index is: " + res);
55+
System.out.println(Arrays.toString(next));
5656
}
5757
}

0 commit comments

Comments
 (0)