Algorithm - How to delete duplicate elements in a list efficiently?

前端 未结 16 2161
执念已碎
执念已碎 2020-12-01 04:21

There is a list L. It contains elements of arbitrary type each. How to delete all duplicate elements in such list efficiently? ORDE

16条回答
  •  佛祖请我去吃肉
    2020-12-01 04:47

    For Java could go with this:

    private static  void removeDuplicates(final List list)
    {
        final LinkedHashSet set;
    
        set = new LinkedHashSet(list); 
        list.clear(); 
        list.addAll(set);
    }
    

提交回复
热议问题