For a particular value of i and j , len [ currRow ] [ j ] stores length of longest common substring in string X [ 0. . i ] and Y [ 0. . j ] .
for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i == 0 j == 0 ) { len [ currRow , j ] = 0 ; } else if ( X [ i - 1 ] == Y [ j - 1 ] ) { len [ currRow , j ] = len [ ( 1 - currRow ) , ( j - 1 ) ] + 1 ; result = Math . Max ( result , len [ currRow , j ] ) ; } else { len [ currRow , j ] = 0 ; } }