Java Array, Finding Duplicates

前端 未结 14 1168
闹比i
闹比i 2020-11-22 09:13

I have an array, and am looking for duplicates.

duplicates = false;
for(j = 0; j < zipcodeList.length; j++){
    for(k = 0; k < zipcodeList.length; k++         


        
14条回答
  •  爱一瞬间的悲伤
    2020-11-22 09:52

    You can use bitmap for better performance with large array.

        java.util.Arrays.fill(bitmap, false);
    
        for (int item : zipcodeList)
            if (!bitmap[item]) bitmap[item] = true;
            else break;
    

    UPDATE: This is a very negligent answer of mine back in the day, keeping it here just for reference. You should refer to andersoj's excellent answer.

提交回复
热议问题