简体   繁体   English

这个程序的运行时复杂度是多少?(esp retainAll()方法)

[英]What is the runtime complexity of this program?(esp retainAll() method)

public static List<Integer> returnIntersection(List<Integer> a,List<Integer> b){

    List<Integer> l1=new ArrayList<Integer>(a);
    List<Integer> l2=new ArrayList<Integer>(b);
    l1.retainAll(l2);//find intersection in l2
    l1=removeDuplicates(l1);
    return l1;}

public static List<Integer> removeDuplicates(List<Integer> l) {

Set<Integer> se=new HashSet<Integer>(l);
l.clear();
l=new ArrayList<Integer>(se);
return l;}

The code above is to return a list containing intersection of 2 lists without duplicates.My question is what is time complexity of this? 上面的代码是返回一个包含2个列表的交集的列表,没有重复。我的问题是这个时间复杂度是多少? What is time complexity of the retainAll() method? retainAll()方法的时间复杂度是多少? And is there any time consuming while turning lists into sets? 在将列表转换为集合时是否有时间消耗?

An interesting topic is to measure the complexity of individual methods. 一个有趣的主题是衡量个别方法的复杂性。 There are several things that contribute to the complexity. 有几件事情会导致复杂性。

see here how to measure complexity 看这里如何衡量复杂性

It is very good site how to calculate complexity 如何计算复杂度是非常好的网站

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM