-
Notifications
You must be signed in to change notification settings - Fork 2
/
Between Two Sets.cs
49 lines (39 loc) · 1.09 KB
/
Between Two Sets.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections.Generic;
using System.Linq;
class Solution
{
int getTotalX(List<int> a, List<int> b)
{
int result = 0, counter = 1, aMax = a.Max(), bMin = b.Min(), aMaxMultiple = aMax;
while (aMaxMultiple <= bMin)
{
var isFactor = true;
foreach (var item in a)
{
if (aMaxMultiple % item != 0)
{
isFactor = false;
break;
}
}
if (isFactor)
{
foreach (var item in b)
{
if (item % aMaxMultiple != 0)
{
isFactor = false;
break;
}
}
}
if (isFactor)
{
result++;
}
counter++;
aMaxMultiple = aMax * counter;
}
return result;
}
}