2020面试记录

1,用一个循环将两个有序数组合并为一个有序数组

@Test
    public void paixu() {
        int[] a = {1,4,7,9};
        int[] b = {2,5,8,10};
        int[] c = new int[a.length+b.length];
        int i=0;
        int j=0;
        int k=0;
        while(i<a.length||j<b.length) {
            if(i==a.length && j<b.length) {
                c[k++]=b[j++];
            }else if(i<a.length && j==b.length) {
                c[k++]=a[i++];
            }else if(a[i]>b[j]){
                c[k++]=b[j++];
            }else if(a[i]<=b[j]){
                c[k++]=a[i++];
            }
        }
        for(int val:c) {
            System.out.print(","+val);
        }
    }

2,去除list重复值的三种方法

//一,
    public void frist() {
        List list = getList();
        for(int i=0;i<list.size()-1;i++) {
            for(int j=list.size()-1;j>i;j--) {
                if(list.get(i)==list.get(j)) {
                    list.remove(j);
                }
            }
        }
        System.out.println(list.toString());
    }
    //
    public void secend() {
        List list = getList();
        HashSet hs = new HashSet(list);
        list.clear();
        list.addAll(hs);
        System.out.println(list.toString());
    }
    ////@Test
    public void third() {
        List list = getList();
        List list2 = new ArrayList();
        list2.add(list.get(0));
        for(int i=1;i<list.size();i++) {
            if(!list2.contains(list.get(i))) {
                list2.add(list.get(i));
            }
        }
        System.out.println(list2.toString());
        
    }

3,Integer的相关源码知识

https://blog.csdn.net/w893932747/article/details/87902149

posted @ 2020-02-22 12:32  存钱罐  阅读(221)  评论(0编辑  收藏  举报