题解 | 最长公共子串

最长公共子串

https://www.nowcoder.com/practice/02e7cc263f8a49e8b1e1dc9c116f7602

class LongestSubstring {
public:
    int findLongest(string A, int n, string B, int m) {
       
       vector<vector<int>> dp(n+1,vector<int>(m+1,0));
        int maxx=0;
       for(int i=1;i<=n;i++)
       {
        for(int j=1;j<=m;j++)
        {
            if(A[i-1]==B[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
                maxx=max(maxx,dp[i][j]);
            }
        }
       }
       return maxx;
    }
};

全部评论

相关推荐

柱柱想躺平:这是好事啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务