小试牛刀

有序序列判断

http://www.nowcoder.com/questionTerminal/22e87f8a8d764a6582710f38d1b40c6e

杀鸡牛刀:

import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> v = new ArrayList<>();
        while (sc.hasNext()) v.add(sc.nextInt());
        List<Integer> v1 = new ArrayList<>(v);
        List<Integer> v2 = new ArrayList<>(v);
        Collections.sort(v1, (a, b)->a - b);
        Collections.sort(v2, (a, b)->b - a);
        if(v.equals(v1) || v.equals(v2)) System.out.println("sorted");
        else System.out.println("unsorted");
    }
}
全部评论

相关推荐

LastWh1spe...:ssob真有些人和那个没睡醒一样
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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