题解HJ80 | #整型数组合并#

整型数组合并

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

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int count1 = Integer.valueOf(in.nextLine());
        String[] strings1 = in.nextLine().split(" ");

        int count2 = Integer.valueOf(in.nextLine());
        String[] strings2 = in.nextLine().split(" ");

        Set<Integer> set = new LinkedHashSet<>();

        for (int i = 0; i < count1; i++) {
            set.add(Integer.valueOf(strings1[i]));
        }

        for (int i = 0; i < count2; i++) {
            set.add(Integer.valueOf(strings2[i]));
        }

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

        for (Integer item : list) {
            System.out.print(item);
        }
    }
}

全部评论

相关推荐

01-14 12:34
门头沟学院 C++
牛马人的牛马人生:太暖心了啊 配环境是真烦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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