-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindLonleyInteger.linq
More file actions
51 lines (42 loc) · 1.21 KB
/
FindLonleyInteger.linq
File metadata and controls
51 lines (42 loc) · 1.21 KB
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
50
51
<Query Kind="Program">
<Namespace>System</Namespace>
<Namespace>System.CodeDom.Compiler</Namespace>
<Namespace>System.Collections</Namespace>
<Namespace>System.Collections.Generic</Namespace>
<Namespace>System.ComponentModel</Namespace>
<Namespace>System.Diagnostics.CodeAnalysis</Namespace>
<Namespace>System.Globalization</Namespace>
<Namespace>System.IO</Namespace>
<Namespace>System.Linq</Namespace>
<Namespace>System.Reflection</Namespace>
<Namespace>System.Runtime.Serialization</Namespace>
<Namespace>System.Text</Namespace>
<Namespace>System.Text.RegularExpressions</Namespace>
</Query>
class Result
{
/*
* Complete the 'lonelyinteger' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY a as parameter.
*/
public static int lonelyinteger(List<int> a)
{
var freq = new Dictionary<int, int>();
for (int i = 0; i < a.Count ; i++)
{
if (!freq.ContainsKey(a[i]))
{
freq.Add(a[i], 1);
continue;
}
freq[a[i]]++;
}
return freq.FirstOrDefault(x => x.Value == 1).Key;
}
}
public static void Main(string[] args)
{
Console.WriteLine(Result.lonelyinteger(new List<int>() { 1, 2, 4, 5, 2, 1, 4 }));
}