Merge branch 'master' into patch06

This commit is contained in:
程序员Carl
2022-06-02 08:37:02 +08:00
committed by GitHub
85 changed files with 2774 additions and 277 deletions

View File

@@ -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;
}
```
## 相关题目