public static int findDuplicate(LongList unsorted) {
final LongArray sorted = new LongArray(unsorted);
final IntArray perms = new IntArray(IntProgression.arithmetic(0, sorted.size()));
IntegersUtils.quicksort(sorted.size(),
LongFunctions.comparator(sorted),
new IntIntProcedure() {
@Override
public void invoke(int a, int b) {
sorted.swap(a, b);
perms.swap(a, b);
}