题解 | #整型数组合并#

整型数组合并

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();
    }
}














全部评论

相关推荐

点赞 评论 收藏
分享
看到这个内容真是闹麻了。。。。。。现在有了AI以后很多人面试都会作弊吗?&nbsp;那对老老实实面试的人岂不是不公平....
程序员牛肉:公平那是对小孩子讲的童话故事,成年人的世界只有能不能接受失败的后果。 你要是能接受面试作弊被发现之后多家公司联合永久拉黑的后果,你就搞。
点赞 评论 收藏
分享
05-26 22:25
门头沟学院 Java
Java小肖:不会是想叫你过去把你打一顿吧,哈哈哈
点赞 评论 收藏
分享
06-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务