/* https://github.com/zhedahht/ChineseCodingInterviewAppendix/blob/master/DuplicationInArray/FindDuplication.cpp * Question Description: * An array contains n numbers ranging from 0 to n-1. * There are some numbers duplicated in the array. It is not clear how many numbers are duplicated or * how many times a number gets duplicated. How do you find a duplicated number in the array? * For example, if an array of length 7 contains the numbers {2, 3, 1, 0, 2, 5, 3}, * the implemented function (or method) should return either 2 or 3 */ public class N51DuplicatedNbInArray { public static void main(String[] args) { int[] array = {2, 3, 1, 0, 2, 5, 3}; findDuplicatedNb(array); findDuplicate(array); } public static int findDuplicatedNb(int[] array) { if(array == null || array.length == 0) { throw new IllegalArgumentException("invalid array"); } HashMap appears = new HashMap(); for(int i=0; i numbers.length-1) { return -1; } } for(int i=0; i