File tree 3 files changed +49
-0
lines changed
solution/0300-0399/0349.Intersection of Two Arrays
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,24 @@ class Solution {
183
183
}
184
184
```
185
185
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
+
186
204
### ** ...**
187
205
188
206
```
Original file line number Diff line number Diff line change @@ -165,6 +165,24 @@ class Solution {
165
165
}
166
166
```
167
167
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
+
168
186
### ** ...**
169
187
170
188
```
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments