File tree Expand file tree Collapse file tree 1 file changed +13
-19
lines changed
solution/0300-0399/0350.Intersection of Two Arrays II Expand file tree Collapse file tree 1 file changed +13
-19
lines changed Original file line number Diff line number Diff line change 1
1
public class Solution {
2
2
public int [ ] Intersect ( int [ ] nums1 , int [ ] nums2 ) {
3
3
HashSet < int > hs1 = new HashSet < int > ( nums1 . Concat ( nums2 ) . ToArray ( ) ) ;
4
- Dictionary < int , int > dict = new Dictionary < int , int > ( ) ;
4
+ Dictionary < int , int > dict = new Dictionary < int , int > ( ) ;
5
5
List < int > result = new List < int > ( ) ;
6
6
7
- foreach ( int value in hs1 ) {
8
- dict [ value ] = 0 ;
7
+ foreach ( int x in hs1 ) {
8
+ dict [ x ] = 0 ;
9
9
}
10
10
11
- foreach ( int value in nums1 )
12
- {
13
- if ( dict . ContainsKey ( value ) )
14
- {
15
- dict [ value ] += 1 ;
16
- }
17
- else
18
- {
19
- dict [ value ] = 1 ;
11
+ foreach ( int x in nums1 ) {
12
+ if ( dict . ContainsKey ( x ) ) {
13
+ dict [ x ] += 1 ;
14
+ } else {
15
+ dict [ x ] = 1 ;
20
16
}
21
17
}
22
18
23
- foreach ( int value in nums2 )
24
- {
25
- if ( dict [ value ] > 0 )
26
- {
27
- result . Add ( value ) ;
28
- dict [ value ] -= 1 ;
19
+ foreach ( int x in nums2 ) {
20
+ if ( dict [ x ] > 0 ) {
21
+ result . Add ( x ) ;
22
+ dict [ x ] -= 1 ;
29
23
}
30
24
}
31
25
32
26
return result . ToArray ( ) ;
33
27
}
34
- }
28
+ }
You can’t perform that action at this time.
0 commit comments