Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 18c4b00

Browse files
feat: add csharp solution to lc problem: No.0349 (#1924)
1 parent 615e1e8 commit 18c4b00

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

‎solution/0300-0399/0349.Intersection of Two Arrays/README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,24 @@ class Solution {
183183
}
184184
```
185185

186+
### **C#**
187+
188+
```cs
189+
public class Solution {
190+
public int[] Intersection(int[] nums1, int[] nums2) {
191+
List<int> result = new List<int>();
192+
HashSet<int> arr1 = new(nums1);
193+
HashSet<int> arr2 = new(nums2);
194+
foreach (int x in arr1) {
195+
if (arr2.Contains(x)) {
196+
result.Add(x);
197+
}
198+
}
199+
return result.ToArray();
200+
}
201+
}
202+
```
203+
186204
### **...**
187205

188206
```

‎solution/0300-0399/0349.Intersection of Two Arrays/README_EN.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ class Solution {
165165
}
166166
```
167167

168+
### **C#**
169+
170+
```cs
171+
public class Solution {
172+
public int[] Intersection(int[] nums1, int[] nums2) {
173+
List<int> result = new List<int>();
174+
HashSet<int> arr1 = new(nums1);
175+
HashSet<int> arr2 = new(nums2);
176+
foreach (int x in arr1) {
177+
if (arr2.Contains(x)) {
178+
result.Add(x);
179+
}
180+
}
181+
return result.ToArray();
182+
}
183+
}
184+
```
185+
168186
### **...**
169187

170188
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class Solution {
2+
public int[] Intersection(int[] nums1, int[] nums2) {
3+
List<int> result = new List<int>();
4+
HashSet<int> arr1 = new(nums1);
5+
HashSet<int> arr2 = new(nums2);
6+
foreach (int x in arr1) {
7+
if (arr2.Contains(x)) {
8+
result.Add(x);
9+
}
10+
}
11+
return result.ToArray();
12+
}
13+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /