剑指offer-50-数组重复数字
数组中重复的数字
http://www.nowcoder.com/questionTerminal/623a5ac0ea5b4e5f95552655361ae0a8
思路
用一个数组当作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; } }
剑指offer与数据结构 文章被收录于专栏
本专栏包括剑指offer题目和一些刷题用的数据结构,单调栈,树状数组,差分数组,后面还会更新红黑树等较为复杂的数据结构