Leetcode算法题1101-1200


1101-1110

1111-1120

1143.最长公共子序列

class Solution {
public:
    int longestCommonSubsequence(string text1, string text2) {
        const int N = text1.size(), M = text2.size();
        vector <vector<int>> f(N + 1, vector<int>(M + 1, 0));
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                if (text1[i - 1] == text2[j - 1]) f[i][j] = f[i - 1][j - 1] + 1;
                else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
            }
        }
        return f[N][M];
    }
};

1121-1130

1131-1140

1141-1150

1151-1160

1161-1170

1171-1180

1181-1190

1191-1200


文章作者: 不二
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 不二 !
  目录