题解 | 小苯的麦克斯-java

小苯的麦克斯

https://www.nowcoder.com/practice/de5b60b23a014f1bb66b8164faea3d0d

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while (t-->0) {
            int n=sc.nextInt();
            int[]a=new int[n];
            for (int i = 0; i < a.length; i++) {
                a[i]=sc.nextInt();
            }
            int ans=Integer.MIN_VALUE;
            for (int i = 0; i < n-1; i++) {
                int v1=a[i];
                int v2=a[i+1];
                int m=Math.max(v1, v2);
                int mex;
                if(v1!=0&&v2!=0){
                    mex=0;
                }else if(v1!=1&&v2!=1){
                    mex=1;
                }else{
                    mex=2;
                }
                ans=Math.max(ans, m-mex);
            }
            System.out.println(ans);
        }
        sc.close();
    }
}

#java#
全部评论

相关推荐

找工作勤劳小蜜蜂:矛盾是没有实习,就是没实战经验,公司不想要,公司不要,你就没有实习,你就进入死循环,另外你的项目不是社会现在有大量岗位存在行业用的,云存储人员早就饱和。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务