【发布时间】:2016-06-30 05:35:03
【问题描述】:
下面我的方法的最佳情况和最坏情况时间复杂度是多少?
我知道 ArrayList.add() 的时间复杂度为 O(1),但不确定 loaded.stream().distinct().collect(Collectors.toList());
public static int countUnique(WordStream words) {
ArrayList<String> loaded = new ArrayList<String>();
ArrayList<String> empty = new ArrayList<String>();
// Fill loaded with WordStream words
for (String i : words) {
loaded.add(i);
}
empty = (ArrayList<String>) loaded.stream().distinct().collect(Collectors.toList());
return empty.size();
}
【问题讨论】:
标签: java arraylist time-complexity java-stream collectors