标签:color reac solution 相等 title etc for set add
两个数组的交集
public class Solution { public int[] Intersection(int[] nums1, int[] nums2) { //使用哈希集合去重 HashSet<int> hashSet1=new HashSet<int>(nums1); HashSet<int> hashSet2=new HashSet<int>(nums2); List<int> list=new List<int>(); //遍历两哈希集合,相等者加入集合,遍历结束后将集合转为数组返回 foreach(int h1 in hashSet1){ foreach(int h2 in hashSet2){ if(h1==h2)list.Add(h1); } } return list.ToArray<int>(); } }
标签:color reac solution 相等 title etc for set add
原文地址:https://www.cnblogs.com/errornull/p/10095741.html