Leetcode—1143. 最长公共子序列【中等】

2024每日刷题(155)

Leetcode---1143. 最长公共子序列

实现代码

cpp 复制代码
class Solution {
public:
    int longestCommonSubsequence(string text1, string text2) {
        int m = text1.length();
        int n = text2.length();

        vector<vector<int>> dp(m + 1, vector<int>(n + 1));
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                dp[i + 1][j + 1] = text1[i] == text2[j] ? 1 + dp[i][j] : max(dp[i][j + 1], dp[i + 1][j]);
            }
        }   
        return dp[m][n];
    }
};

运行结果

之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

相关推荐
草莓火锅35 分钟前
用c++使输入的数字各个位上数字反转得到一个新数
开发语言·c++·算法
j_xxx404_37 分钟前
C++ STL:阅读list源码|list类模拟|优化构造|优化const迭代器|优化迭代器模板|附源码
开发语言·c++
散峰而望1 小时前
C/C++输入输出初级(一) (算法竞赛)
c语言·开发语言·c++·算法·github
Kuo-Teng1 小时前
LeetCode 160: Intersection of Two Linked Lists
java·算法·leetcode·职场和发展
fie88891 小时前
基于MATLAB的狼群算法实现
开发语言·算法·matlab
曾几何时`1 小时前
C++——this指针
开发语言·c++
偷偷的卷2 小时前
【算法笔记 11】贪心策略六
笔记·算法
小冯的编程学习之路2 小时前
【C++】: C++基于微服务的即时通讯系统(1)
开发语言·c++·微服务
ZPC82102 小时前
FPGA 部署ONNX
人工智能·python·算法·机器人
_w_z_j_2 小时前
爱丽丝的人偶
算法