码迷,mamicode.com
首页 > 其他好文 > 详细

1143. 最长公共子序列

时间:2021-02-08 11:51:48      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:com   solution   return   long   stc   ext1   ems   common   class   

class Solution {
public:
    int f[1005][1005];
    int longestCommonSubsequence(string text1, string text2) {
        memset(f,0,sizeof(f));
        int n=text1.size();
        int m=text2.size();
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++){
                if(text1[i-1]==text2[j-1]){
                    f[i][j]=max(f[i][j],f[i-1][j-1]+1);
                }else{
                    f[i][j]=max(f[i][j],max(f[i-1][j],f[i][j-1]));
                }
            }
        return f[n][m];
    }
};

1143. 最长公共子序列

标签:com   solution   return   long   stc   ext1   ems   common   class   

原文地址:https://www.cnblogs.com/rign-lr7rq2truq/p/14382297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!