HJ3 明明的随机数

牛客华为机试题库【题号 HJ开头】(重点看)
牛客在线编程算法篇【题号NC开头】
剑指offer【题号 JZ开头】
力扣

1)原题链接

2)已有题解

3)代码

package array;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;

import static java.lang.Integer.parseInt;
import static java.lang.System.in;

/**
 * HJ3 明明的随机数
 */
public class MingMingRandom {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(in));

        outPut1(bf);

        outPut2(bf);
    }

    private static void outPut1(BufferedReader bf) throws IOException {
        List<Integer> list = new ArrayList<>();

        int num = parseInt(bf.readLine());

        for (int i = 0; i < num; i++) {
            list.add(parseInt(bf.readLine()));
        }
        bf.close();

        list.sort(Comparator.naturalOrder());

        List<Integer> collect = list.stream().sorted().distinct().collect(Collectors.toList());

        collect.forEach(System.out::println);
    }

    private static void outPut2(BufferedReader bf) throws IOException {
        Set<Integer> set = new HashSet<>();

        int num = parseInt(bf.readLine());

        for (int i = 0; i < num; i++) {
            set.add(parseInt(bf.readLine()));
        }
        bf.close();

        List<Integer> collect1 = set.stream().sorted().collect(Collectors.toList());

        collect1.forEach(System.out::println);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值