Lonely Integer

  • + 0 comments

    Here is a solution with C# public static int lonelyinteger(List a) { Dictionary myDict = new Dictionary(a.Count); int result = 0; for(int i = 0; i < a.Count; i++){ if(myDict.ContainsKey(a[i])){ myDict[a[i]] += 1; }else{ myDict.Add(a[i], 1); } } foreach(KeyValuePair item in myDict ){ Console.WriteLine(item.Value+ " "); if(item.Value == 1){ result = item.Key; break; } } return result; }

    }