题解 | #整型数组合并#
整型数组合并
http://www.nowcoder.com/practice/c4f11ea2c886429faf91decfaf6a310b
//treeset 有序,且不重复
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num1 = in.nextInt();
TreeSet ts = new TreeSet<>();//与哈希表有区别
for(int i =0; i<num1; i++){
ts.add(in.nextInt() ); //只添加一个元素
}
int num2 = in.nextInt();
for(int i =0; i<num2; i++){
ts.add(in.nextInt() );
}
Iterator it = ts.iterator();//迭代器遍历集合
while( it.hasNext() ){
System.out.print(it.next());
}
}//main
}//Main
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int num1 = in.nextInt();
TreeSet ts = new TreeSet<>();//与哈希表有区别
for(int i =0; i<num1; i++){
ts.add(in.nextInt() ); //只添加一个元素
}
int num2 = in.nextInt();
for(int i =0; i<num2; i++){
ts.add(in.nextInt() );
}
Iterator it = ts.iterator();//迭代器遍历集合
while( it.hasNext() ){
System.out.print(it.next());
}
}//main
}//Main