标签:
/* * 350. Intersection of Two Arrays II * 2016-7-12 by Mingyang * 这个就用两个指针来做就好了 */ public int[] intersect(int[] nums1, int[] nums2) { List<Integer> list = new ArrayList<Integer>(); Arrays.sort(nums1); Arrays.sort(nums2); int i = 0; int j = 0; while (i < nums1.length && j < nums2.length) { if (nums1[i] < nums2[j]) { i++; } else if (nums1[i] > nums2[j]) { j++; } else { list.add(nums1[i]); i++; j++; } } int[] result = new int[list.size()]; int k = 0; for (Integer num : list) { result[k++] = num; } return result; }
350. Intersection of Two Arrays II
标签:
原文地址:http://www.cnblogs.com/zmyvszk/p/5665627.html