public static void main(String[] args) throws ParseException {
        int[] a = {4,5,-1,-1};
        int[] b = {-1,4,5,-1};
        Integer[] c = intersection2(a,b);
        System.out.println(Arrays.toString(c));
    }


    public static  Integer[] intersection2(int[] nums1, int[] nums2) {
        int i = 0, j = 0;
        List<Integer> diff = new ArrayList<>();
        while (i < nums1.length && (j < nums2.length)) {
            if (nums1[i] < nums2[j])
                i++;
            else if (nums1[i] > nums2[j])
                j++;
            else {
                diff.add(nums1[i]);
                i++;
                j++;
            }
        }
        Integer[] t = new Integer[diff.size()];
        return diff.toArray(t);
    }
 posted on 2020-11-06 17:02  布诺  阅读(141)  评论(0编辑  收藏  举报