
function LCSubstring(str1, str2){
    var m = str1.length;
    var n = str2.length;
    var dp = [new Array(n+1).fill(0)];
    var lastIndex = 0, maxLength;
    for(var i = 1; i <= m; i++){
        dp[i] = [0];
        for(var j = 1; j <= n; j++){
            if(str1[i-1] === str2[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
                if( dp[i][j] > maxLength){
                    maxLength = dp[i][j];
                    lastIndex = j - 1;
                }

            }else{
                dp[i][j] = 0;
            }
        }
        console.log(dp[i]);
    }
    console.log("它们最长公共子串为 "+str1.substr(lastIndex,maxLength));
    return dp[m][n];   //dp[n1-1][n2-1]
}
var c = LCSubstring("acbac","acaccbabb");
console.log(c);
   