[蓝桥杯] 查找整数(使用散列映射)

    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int leng = in.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < leng; i++) {
            map.putIfAbsent(in.nextInt(), i + 1);
        }
        System.out.println(map.getOrDefault(in.nextInt(), -1));
    }

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据