You could sort the numbers first, using an efficient algorithm such as quick sort or merge sort, and then just compare each number with the next one.