题解 | #整型数组合并#

整型数组合并

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


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            Set<Integer> set = new TreeSet<>();
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                set.add(sc.nextInt());
            }
            int m = sc.nextInt();
            for (int i = 0; i < m; i++) {
                set.add(sc.nextInt());
            }
            ArrayList<Integer> list = new ArrayList<>(set);
            for (int i = 0; i < list.size(); i++) {
                if(i == list.size()-1){
                    System.out.println(list.get(i));
                }else{
                    System.out.print(list.get(i));
                }
            }
        }
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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