p [ 1 ] = 0 ;
char [ ] ch1 = str1 . ToCharArray ( ) ; char [ ] ch2 = str2 . ToCharArray ( ) ; for ( int i = 2 ; i <= n ; i ++ ) { while ( k > 0 && ch1 [ k ] != ch1 [ i - 1 ] ) k = p [ k ] ; if ( ch1 [ k ] == ch1 [ i - 1 ] ) ++ k ; p [ i ] = k ; }