求两个数组的重复数据
2021-09-18 04:13
标签:public else stat out sort list cti 重复 pointer public class DoublePointer { public static int[] a = new int[]{1, 3, 4, 9}; public static int[] b = new int[]{0, 3, 4, 4}; public static void main(String[] args) { System.out.println("两个数组重合数据为:" + intersection(a, b)); } public static List intersection(int[] a, int[] b) { //a 或者 b 有一个为null,则返回null if (a == null || b == null) { return null; } //设置最小的位数 List temp = new ArrayList(); //首先排序,从小到大 Arrays.sort(a); Arrays.sort(b); for (int i = 0, j = 0; i b[j]) { j++; } else { i++; } } return temp; } } 求两个数组的重复数据标签:public else stat out sort list cti 重复 pointer 原文地址:https://www.cnblogs.com/Small-sunshine/p/14885934.html