using System;
using System.Collections.Generic;
class FindElementThatAppearsOnceInArray_CSharp
{
public static int FindElementThatAppearsOnceInArray(int[] arr)
{
Dictionary<int, int> map = new Dictionary<int, int>();
foreach (int x in arr) {
if (map.ContainsKey(x)) {
map[x]++;
}
else {
map[x] = 1;
}
}
foreach (KeyValuePair<int, int> entry in map) {
if (entry.Value == 1) {
return entry.Key;
}
}
return -1;
}
public static void Main(string[] args)
{
int[] arr = new int[] { 3, 5, 5, 2, 7, 3, 2, 8, 8, 3, 2, 5, 8 };
Console.WriteLine(FindElementThatAppearsOnceInArray(arr));
}
}
/*
run:
7
*/