Skip to content

Commit 09a42b1

Browse files
authored
Update Solution.cs
1 parent 197bdcc commit 09a42b1

File tree

1 file changed

+13
-19
lines changed
  • solution/0300-0399/0350.Intersection of Two Arrays II

1 file changed

+13
-19
lines changed
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
public class Solution {
22
public int[] Intersect(int[] nums1, int[] nums2) {
33
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>();
55
List<int> result = new List<int>();
66

7-
foreach(int value in hs1){
8-
dict[value] = 0;
7+
foreach (int x in hs1) {
8+
dict[x] = 0;
99
}
1010

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;
2016
}
2117
}
2218

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;
2923
}
3024
}
3125

3226
return result.ToArray();
3327
}
34-
}
28+
}

0 commit comments

Comments
 (0)