题解 | #整型数组合并#

整型数组合并

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

利用TreeSet集合的特性(去重、有序)即可

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

/**
 * 【整型数组合并】
 *
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        TreeSet<Integer> treeSet = new TreeSet<>();

        int lengthOne = sc.nextInt();
        for (int i = 0; i < lengthOne; i++) {
            treeSet.add(sc.nextInt());
        }

        int lengthTwo = sc.nextInt();
        for (int i = 0; i < lengthTwo; i++) {
            treeSet.add(sc.nextInt());
        }
        
        for (Integer integer : treeSet) {
            System.out.print(integer);
        }
    }
}

全部评论

相关推荐

菜菜狗🐶:双非之光
找工作,你会甘心进小厂还...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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