题解 | #整型数组合并#
整型数组合并
https://www.nowcoder.com/practice/c4f11ea2c886429faf91decfaf6a310b
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); int[] num1 = new int[n]; //构造第一个数组 for (int i = 0; i < n; i++) { num1[i] = sc.nextInt(); } //构造第二数组 int m = sc.nextInt(); int[] num2 = new int[m]; for (int i = 0; i < m; i++) { num2[i] = sc.nextInt(); } //合并数组 Set<Integer> set = new TreeSet<>(); for (int i = 0; i < n; i++) { set.add(num1[i]); } for (int i = 0; i < m; i++) { set.add(num2[i]); } //输出数组 for (Integer k : set) { System.out.print(k); } } } }#整型数组合并#