提问人:Eugene Shevchugov 提问时间:11/20/2020 更新时间:11/20/2020 访问量:95
列表中的 SubString
SubString in List
问:
我有一个类和方法
class Dictionary {
public Dictionary(List<String> dic) {
// ...
}
public int getCount(String substr) {
// ...
}
}
应该发生什么:
在方法 getCount 中,您需要使用类构造函数中的列表并查找从子字符串子线程开始的所有字符串
我在面试中使用了这个解决方案
return (int) this.dic.stream().filter(s -> s.startsWith(substr)).count();
复杂度为 O(n)
有更好的解决方案吗?
谢谢!
答: 暂无答案
上一个:Java 中的联合流 [已关闭]
评论