function lcs_search(str1, str2){
    var len1 = str1.length;
    var len2 = str2.length;
    var dp_arr = [[],[]]
    var pre = 1
    var now = 0
    var result =0
    var result_pos = []

    for (var i = 0; i <= len2+1; i ++) {
        dp_arr[0][i] = 0
        dp_arr[1][i] = 0
    }
    for (var i = 0; i <= len1; i ++) {
        for (var j = 0; j <= len2; j ++) {
            if ( i == 0 || j == 0 ){
                dp_arr[now][j] = 0
            }
            else if ( str1[i-1] == str2[j-1] ) {
                dp_arr[now][j] = dp_arr[pre][j-1] + 1
                if (dp_arr[now][j] > result){
                    result = dp_arr[now][j]
                    result_pos = [i - result]
                }else if (dp_arr[now][j] == result){
                    result_pos.push( i - result )
                }
            }
            else {
                dp_arr[now][j] = 0
            }
        }
        if( now == 0 ){
            now = 1
            pre = 0
        }
        else {
            now = 0
            pre = 1
        }
    }
    var result_pos_set = new Set(result_pos)
    var result_str = new Set()
    for (var item of result_pos_set) {
        result_str.add(str1.substr(item, result))
    }
    return Array.from(result_str)
}
// Find the longest common substring of str1 and str2, and return an array of all the longest substrings
Find the longest common substring of str1 and str2, and return an array of all the longest substrings
Find the longest common substring of str1 and str2 and return an array of all the longest substrings
function lcs_search(str1, str2){
    var len1 = str1.length;
    var len2 = str2.length;
    var dp_arr = [[],[]]
    var pre = 1
    var now = 0
    var result =0
    var result_pos = []
    for (var i = 0; i <= len2+1; i ++) {
        dp_arr[0][i] = 0
        dp_arr[1][i] = 0
    }
    for (var i = 0; i <= len1; i ++) {
        for (var j = 0; j <= len2; j ++) {
            if ( i == 0 || j == 0 ){
                dp_arr[now][j] = 0
            }
            else if ( str1[i-1] == str2[j-1] ) {
                dp_arr[now][j] = dp_arr[pre][j-1] + 1
                if (dp_arr[now][j] > result){
                    result = dp_arr[now][j]
                    result_pos = [i - result]
                }else if (dp_arr[now][j] == result){
                    result_pos.push( i - result )
                }
            }
            else {
                dp_arr[now][j] = 0
            }
        }
        if( now == 0 ){
            now = 1
            pre = 0
        }
        else {
            now = 0
            pre = 1
        }
    }
    var result_pos_set = new Set(result_pos)
    var result_str = new Set()
    for (var item of result_pos_set) {
        result_str.add(str1.substr(item, result))
    }
    return Array.from(result_str)
}
function lcs_search ( str1 , str2 ) { var len1 = str1 . length ; var len2 = str2 . length ; var dp_arr = [ [ ] , [ ] ] var pre = 1 var now = 0 var result = 0 var result_pos = [ ] for ( var i = 0 ; i <= len2 + 1 ; i ++ ) { dp_arr [ 0 ] [ i ] = 0 dp_arr [ 1 ] [ i ] = 0 } for ( var i = 0 ; i <= len1 ; i ++ ) { for ( var j = 0 ; j <= len2 ; j ++ ) { if ( i == 0 || j == 0 ) { dp_arr [ now ] [ j ] = 0 } else if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) { dp_arr [ now ] [ j ] = dp_arr [ pre ] [ j - 1 ] + 1 if ( dp_arr [ now ] [ j ] > result ) { result = dp_arr [ now ] [ j ] result_pos = [ i - result ] } else if ( dp_arr [ now ] [ j ] == result ) { result_pos . push ( i - result ) } } else { dp_arr [ now ] [ j ] = 0 } } if ( now == 0 ) { now = 1 pre = 0 } else { now = 0 pre = 1 } } var result_pos_set = new Set ( result_pos ) var result_str = new Set ( ) for ( var item of result_pos_set ) { result_str . add ( str1 . substr ( item , result ) ) } return Array . from ( result_str ) }
Find the longest common substring of str1 and str2, and return an array of all the longest substrings
Find the longest common substring of str1 and str2 and return an array of all the longest substrings