题解 | #等差数列#

等差数列

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        int [] array = new int [n];
        for(int i = 0;i<n;i++){
            array[i] = in.nextInt();
        }
        Arrays.sort(array);
        int d = array[1]-array[0];
        boolean judge = true;
        for(int i = 2;i<n;i++){
            if(array[i]-array[i-1]!=d)  {
                judge=false;
                break;
            }
        }
        if(judge)   System.out.println("Possible");
        else   System.out.println("Impossible");
    }
}

排序一下就可以。

全部评论

相关推荐

半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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