作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
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;}
上面的代码是返回一个列表,其中包含 2 个列表的交集,没有重复项。我的问题是这个的时间复杂度是多少? retainAll() 方法的时间复杂度是多少?列表转集合是否耗时?
最佳答案
关于java - 这个程序的运行时复杂度是多少?(尤其是 retainAll() 方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15491934/
我是一名优秀的程序员,十分优秀!