C# Distinct
static int Distinct(int[] a)
{
    return new HashSet<int>(a).Count;
}

This counts unique values by tracking what has already been seen.