AcWing 2816. 判断子序列 Java
原题链接
简单
作者:
leo_0
,
2021-07-21 13:56:42
,
所有人可见
,
阅读 189
算法1
Java 代码
import java.util.*;
import java.io.*;
public class Main {
static int[] nums;
final static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
final static BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException{
String[] str = reader.readLine().split("\\s+");
int n = Integer.parseInt(str[0]);
int m = Integer.parseInt(str[1]);
int[] a = new int[n];
int[] b = new int[m];
str = reader.readLine().split("\\s+");
for(int i = 0; i < n; i++){
a[i] = Integer.parseInt(str[i]);
}
str = reader.readLine().split("\\s+");
for(int i = 0; i < m; i++){
b[i] = Integer.parseInt(str[i]);
}
if(check(a, n, b, m)){
System.out.print("Yes");
}else{
System.out.print("No");
}
}
private static boolean check(int[] a, int n, int[] b, int m){
int i = 0;
int j = 0;
while(i < n && j < m){
if(a[i] == b[j]){
i++;
}
j++;
}
return i == n;
}
}