static IEnumerable<T> FindUniqueNumbersInCollection<T>(ICollection<T> value)
{
Dictionary<T, byte> hash = new Dictionary<T, byte>();
foreach (T val in value)
{
if (hash.ContainsKey(val)) { hash[val] = 1; continue; }
hash.Add(val, 0);
}
List<T> unique = new List<T>();
foreach (KeyValuePair<T, byte> kvp in hash)
{
if (kvp.Value == 0) unique.Add(kvp.Key);
}
return unique;
}
static IEnumerable<T> FindUniqueNumbersInCollection<T>(ICollection<T> value) { Dictionary<T, byte> hash = new Dictionary<T, byte>(); foreach (T
Share
Edit:
I think this is finally correct. 🙂
Or if you’d like some LINQ:
Or even
I wouldn’t say it’s "more efficient" than yours (it’s really not — they’re pretty much the same), but it’s definitely shorter.
If you want overkill efficiency (at the cost of accuracy), you can always use a Bloom Filter!