KMP算法实现查找字符串第一次出现的位置
package ten_algorithm . kmp ; import ten_algorithm . dynamic . KnapSack ; import java . util . Arrays ; /** * Author:jinpma * Date :2019/12/28 */ public class KmpSearch { public static void main ( String [ ] args ) { String str1 = "BBC ABCDAB ABCDABCDABDE" ; String str2 = "ABCDABD" ; KmpSearch k = new KmpSearch ( ) ; int [ ] next = k . next ( str2 ) ; int index = k . findIndex ( str1 , str2 , next ) ; System . out . println ( index ) ; } private int findIndex ( String str1 , String str2 , int [ ] next ) { int i , j ; for ( i = 0 , j = 0 ; i < str1 . length ( ) ; i ++ ) { if ( str1 . charAt ( i