How to efficiently remove duplicates from an array without using Set

后端 未结 30 2802
情深已故
情深已故 2020-11-22 07:29

I was asked to write my own implementation to remove duplicated values in an array. Here is what I have created. But after tests with 1,000,000 elements it took very long ti

30条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 07:36

    class Demo 
    {
        public static void main(String[] args) 
        {
            int a[]={3,2,1,4,2,1};
            System.out.print("Before Sorting:");
            for (int i=0;ia[j])
                    {
                        int temp=a[i];
                        a[i]=a[j];
                        a[j]=temp;
                    }
    
                }
            }
    
            //After sorting
            for(int i=0;i

提交回复
热议问题