题解 | #集合#

集合

https://www.nowcoder.com/practice/635ff765d4af45b5bf8e3756ed415792

import java.util.Scanner;
import java.util.TreeSet;

/**
 * JD7 集合
 * @author d3y1
 */
public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        while(in.hasNext()){
            solution(in);
        }
    }

    /**
     * 模拟法: TreeSet
     * @param in
     */
    private static void solution(Scanner in){
        int n = in.nextInt();
        int m = in.nextInt();

        TreeSet<Integer> set = new TreeSet<>();
        for(int i=1; i<=n+m; i++){
            set.add(in.nextInt());
        }

        for(Integer value: set){
            System.out.print(value+" ");
        }
    }
}

全部评论

相关推荐

07-10 14:08
已编辑
江西农业大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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