-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindOutlier.cs
41 lines (38 loc) · 950 Bytes
/
FindOutlier.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
using System.Collections.Generic;
using System.Linq;
using System;
namespace CodeWars
{
public static class FindOutlier
{
public static int Find(int[] integers)
{
int result = 0;
var sample = integers.Take(3);
bool outlierIsEven = sample.Where(x => x % 2 == 0).Count() < 2;
if(outlierIsEven)
{
foreach (var ele in integers)
{
if (ele % 2 == 0)
{
result = ele;
break;
}
}
}
else
{
foreach (var ele in integers)
{
if (ele % 2 != 0)
{
result = ele;
break;
}
}
}
return result;
}
}
}