-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask1.cs
28 lines (24 loc) · 833 Bytes
/
task1.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
/*
----------------------------------------------------------------
https://www.codewars.com/kata/57f609022f4d534f05000024/train/csharp
----------------------------------------------------------------
*/
using System;
using System.Collections.Generic;
class Solution{
public static int Stray(int[] numbers){
List<int> firstGroup = new List<int> { };
List<int> secondGroup = new List<int> { };
for(int i = 0; i < numbers.Length; i++){
if(i == 0){
firstGroup.Add(numbers[i]);
}
else{
if (numbers[i] == firstGroup[0]) firstGroup.Add(numbers[i]);
else secondGroup.Add(numbers[i]);
}
}
if (firstGroup.Count > secondGroup.Count) return secondGroup[0];
else return firstGroup[0];
}
}