15 August 2017

firstDuplicate

My solution:
int firstDuplicate(int[] a) 
{
    var list = new SortedSet<int>();
    foreach (int d in a)
    {
        if (list.Contains(d))
            return d;
        
        list.Add(d);
    }
    
    return -1;
}

Next