数组合并(Java)

整形数组合并

http://www.nowcoder.com/questionTerminal/c4f11ea2c886429faf91decfaf6a310b

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            Set<Integer> set = new HashSet<>();
            int n1 = in.nextInt();
            for (int i = 0; i < n1; i++){
                set.add(in.nextInt());
            }
            int n2 = in.nextInt();
            for (int i = 0; i < n2; i++){
                set.add(in.nextInt());
            }
            int n3 = set.size();
            int[] arr = new int[n3];
            int k = 0;
            for (int i : set){
                arr[k] = i;
                k++;
            }
            Arrays.sort(arr);
            String res = "";
            for (int i = 0; i < n3; i++){
                res += arr[i];
            }
            System.out.println(res);
        }
    }
}
全部评论

相关推荐

joe2333:怀念以前大家拿华为当保底的日子
点赞 评论 收藏
分享
点赞 1 评论
分享
牛客网
牛客企业服务