Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最长公共子序列 #308

Open
Sunny-117 opened this issue Nov 8, 2022 · 1 comment
Open

最长公共子序列 #308

Sunny-117 opened this issue Nov 8, 2022 · 1 comment

Comments

@Sunny-117
Copy link
Owner

No description provided.

@dossweet
Copy link
Contributor

dossweet commented Jan 17, 2023

动态规划经典题目!

const LCS = function (strA, strB) {
    let dp = new Array(strA.length + 1).fill(0).map(item => new Array(strB.length + 1).fill(0));
    for (let i = 1; i <= strA.length; i++) {
        for (let j = 1; j <= strB.length; j++) {
            if (strA[i] === strB[j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }
    return dp[strA.length][strB.length];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants