AcWing 2816. 判断子序列
原题链接
简单
作者:
Broken_
,
2024-09-25 17:37:19
,
所有人可见
,
阅读 3
java 代码
import java.io.BufferedInputStream;
import java.util.Scanner;
/**
* 判断子序列
*/
public class Main {
private static final int N = 100010;
private static int[] a = new int[N];
private static int[] b = new int[N];
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedInputStream(System.in));
int n = sc.nextInt();
int m = sc.nextInt();
for (int i = 0; i < n; i++) a[i] = sc.nextInt();
for (int i = 0; i < m; i++) b[i] = sc.nextInt();
int i = 0, j = 0;
while (i < n && j < m) {
if (a[i] == b[j]) i++;
j++;
}
if (i == n) System.out.println("Yes");
else System.out.println("No");
}
}