Merge branch 'master' into patch06
This commit is contained in:
@@ -312,6 +312,7 @@ int* intersection1(int* nums1, int nums1Size, int* nums2, int nums2Size, int* re
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
Scala:
|
||||
|
||||
正常解法:
|
||||
@@ -354,6 +355,26 @@ object Solution {
|
||||
(nums1.distinct).intersect(nums2.distinct)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
C#:
|
||||
```csharp
|
||||
public int[] Intersection(int[] nums1, int[] nums2) {
|
||||
if(nums1==null||nums1.Length==0||nums2==null||nums1.Length==0)
|
||||
return new int[0]; //注意数组条件
|
||||
HashSet<int> one = Insert(nums1);
|
||||
HashSet<int> two = Insert(nums2);
|
||||
one.IntersectWith(two);
|
||||
return one.ToArray();
|
||||
}
|
||||
public HashSet<int> Insert(int[] nums){
|
||||
HashSet<int> one = new HashSet<int>();
|
||||
foreach(int num in nums){
|
||||
one.Add(num);
|
||||
}
|
||||
return one;
|
||||
}
|
||||
|
||||
```
|
||||
## 相关题目
|
||||
|
||||
|
||||
Reference in New Issue
Block a user