题解 | #整型数组合并#--set去重,数组排序

整型数组合并

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            Set<Integer> set = new HashSet<>();
            int n1 = sc.nextInt();
            for (int i = 0; i < n1; i++) {
                set.add(sc.nextInt());
            }
            int n2 = sc.nextInt();
            for (int i = 0; i < n2; i++) {
                set.add(sc.nextInt());
            }
            int[] arr = new int[set.size()];
            int index = 0;
            for (Integer i : set) {
                arr[index++] = i;
            }
            Arrays.sort(arr);
            for (int i : arr) {
                System.out.print(i);
            }
        }
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务