题目链接:
自己的做法:
cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], b[N];
int main()
{
int n, m;
bool flag = true;
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 j = 0, i = 0;
while (j < m && i < n) {
if (a[i] == b[j]) i++, j++, flag = true;
else j++, flag = false;
}
if (i == n && flag) cout << "Yes";
else cout << "No";
return 0;
}
推荐解法: