题解 | #整型数组合并#

整型数组合并

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String str;
        while((str=br.readLine())!=null&&str.length()>0){
            String[] strs1=br.readLine().split(" "); 
            str=br.readLine();
            String[] strs2=br.readLine().split(" ");
            int[] array=new int[strs1.length+strs2.length];
            for(int i=0;i<strs1.length;i++)
                array[i]=Integer.parseInt(strs1[i]);
            for(int i=strs1.length;i<strs1.length+strs2.length;i++)
                array[i]=Integer.parseInt(strs2[i-strs1.length]);
            Arrays.sort(array);//直接将两个数组合并排序
            StringBuffer sb=new StringBuffer();
            sb.append(array[0]);
            for(int i=1;i<array.length;i++){
                if(array[i]!=array[i-1])
                    sb.append(array[i]);
            }//去重
            System.out.println(sb.toString().trim());
        }
    }


}

#整型数组合并#
全部评论

相关推荐

昨天 16:33
已编辑
微软_sde(实习员工)
点赞 评论 收藏
分享
09-19 13:59
门头沟学院 Java
用微笑面对困难:Trae一下,如果真成了,他用了直接发字节起诉代码版权,,这个代码不商用是没问题的如果没成也是情理之中的。
点赞 评论 收藏
分享
11-04 10:30
已编辑
门头沟学院 研发工程师
开心小狗🐶:“直接说答案”
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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