题解 | #整型数组合并#
整型数组合并
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());
}
}
}
#整型数组合并#
查看15道真题和解析