You are viewing a single comment's thread. Return to all comments →
int result = 0; Dictionary<int, int> set = []; foreach (int integer in a) { if (!set.ContainsKey(integer)) { set.Add(integer, 1); } else { int value = set[integer]; set[integer] = ++value; } } if (set.Count == 1) { result = set.Keys.FirstOrDefault(); } else { result = set.Where(pair => pair.Value == 1).FirstOrDefault().Key; } return result;
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer
You are viewing a single comment's thread. Return to all comments →