题解 | #整型数组合并#
整型数组合并
http://www.nowcoder.com/practice/c4f11ea2c886429faf91decfaf6a310b
比较重复元素太笨了
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
int n1 = scan.nextInt();
int[] nums1 = new int[n1];
for(int i= 0; i<n1; i++){
nums1[i] = scan.nextInt();
}
int n2 = scan.nextInt();
int[] nums2 = new int[n2];
for(int i = 0; i<n2; i++){
nums2[i] = scan.nextInt();
}
List<Integer> list = new ArrayList<>();
for(int i : nums1){
int count = 0;
for(int j = 0; j<list.size(); j++){
if(list.get(j)!=i){
count++;
}
}
if(count == list.size()){
list.add(i);
}
}
for(int i : nums2){
int count = 0;
for(int j : nums1){
if( j!=i){
count++;
}
}
if(count == nums1.length){
list.add(i);
}
}
list.sort(Comparator.naturalOrder());
for(int i =0; i<list.size(); i++){
System.out.print(list.get(i));
}
}
scan.close();
}
}