Array remove duplicate elements

前端 未结 12 1533
陌清茗
陌清茗 2020-11-27 16:17

I have an unsorted array, what is the best method to remove all the duplicates of an element if present?

e.g:

a[1,5,2,6,8,9,1,1,10,3,2,4,1,3,11,3]
         


        
12条回答
  •  借酒劲吻你
    2020-11-27 16:41

        indexOutput = 1;
        outputArray[0] = arrayInt[0];
        int j;
        for (int i = 1; i < arrayInt.length; i++) {            
            j = 0;
            while ((outputArray[j] != arrayInt[i]) && j < indexOutput) {
                j++;
            }
            if(j == indexOutput){
               outputArray[indexOutput] = arrayInt[i];
               indexOutput++;
            }         
        }
    

提交回复
热议问题