思路

用一个数组当作hash表,本题注意判空数组

代码

public class Solution {
    public boolean duplicate(int numbers[],int length,int [] duplication) {
        duplication[0]=-1;
        if(numbers==null || numbers.length<=0){return false;}
        int[] hash=new int[length];
        for(int i=0;i<numbers.length;i++){
            hash[numbers[i]]++;
            if(hash[numbers[i]]>=2){
                duplication[0]=numbers[i];
                return true;
            }
        }
        return false;
    }
}