当前位置:网站首页>蓝桥杯2019年国赛最长子序列

蓝桥杯2019年国赛最长子序列

2022-06-22 14:25:00 Stephen_Curry___

题目链接:

链接: 最长子序列.

思路

一看到求最长子序列即可想到用双指针算法来求解,题目很简单,模拟一下就可以了。

C++代码

#include<bits/stdc++.h>
using namespace std;
int main(){
    
    string s1, s2;
    cin >> s1 >> s2;
    int len = 0;
    for(int i = 0, j = 0; i < s1.size(); i++){
    
        if(s1[i] == s2[j]){
    
            j++;
            len++;
        }
    }
    cout << len;
    return 0;
}  
原网站

版权声明
本文为[Stephen_Curry___]所创,转载请带上原文链接,感谢
https://blog.csdn.net/stephen_curry___/article/details/124009480