多学习。

【双指针】AcWing 2816. 判断子序列

AcWing2816.判断子序列

题解

即在另一个序列中,找到所有本序列的值,且具有相同的排列

#include <iostream>
#include <cstdio>

using namespace std;

const int N = 1e5+10;

int a[N], b[N];

int main()
{
    int n, m;
    scanf("%d%d",&n, &m);
    for(int i = 0; i < n; ++i) scanf("%d",&a[i]);
    for(int i = 0; i < m; ++i) scanf("%d",&b[i]);
    
    int i = 0, j = 0;
    while(i < n && j < m)
    {
        if(a[i] == b[j]) i++;
        j ++ ;
    }
    
    if(i != n) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}
posted @ 2022-05-09 15:43  czyaaa  阅读(30)  评论(0)    收藏  举报