标签:one .com ati 交集 span rgb each style pre
Given two arrays, write a function to compute their intersection.
Example:
Given nums1 = [1, 2, 2, 1]
, nums2 = [2, 2]
, return [2]
.
Note:
Subscribe to see which companies asked this question
public int[] Intersection(int[] nums1, int[] nums2) {
List<int> l = new List<int>();
List<int> sameList = new List<int>();
int length = nums1.Length;
for (int i = 0; i < length; i++) {
l.Add(nums1[i]);
}
length = nums2.Length;
int num = 0;
for (int i = 0; i < length; i++) {
num = nums2[i];
if (l.Contains(num) && !sameList.Contains(num)) {
sameList.Add(num);
}
}
int [] list = sameList.ToArray();
return list;
}
349.求两个数组的交集 Intersection of Two Arrays
标签:one .com ati 交集 span rgb each style pre
原文地址:http://www.cnblogs.com/xiejunzhao/p/be76b2bc9eee928c4debbb5933430f65.html