题面
核心思想
模拟
需要注意的是 1~n 只会出现一次 所有nums[i] 如果等于x(或y),下一位等不等于y(或x),就可以直接判断出结果了。
代码
import java.util.*;
public class Main {
public static void main(String[] args) {
final long MOD = (long) (1e9 + 7);
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] nums = new int[n];
for(int i = 0; i < n; i++){
nums[i] = scanner.nextInt();
}
int x = scanner.nextInt();
int y = scanner.nextInt();
boolean flag = false;
for(int i = 0; i < n - 1; i++){
if(nums[i] == x){
if(nums[i + 1] == y)
flag = true;
break;
}
if(nums[i] == y){
if(nums[i + 1] == x)
flag = true;
break;
}
}
System.out.println(flag? "Yes":"No");
}
}
标签:届秋招,scanner,真题,int,nums,美的,nextInt,flag
From: https://www.cnblogs.com/ganyq/p/18113539