【发布时间】:2014-08-13 02:21:41
【问题描述】:
我想从 expList 中统计 textToBeTested 数组中是否存在单词。
请注意,expList 和 textToBeTested 数组都可以非常大。
我可以简单地遍历两个列表并使用“.matches”方法进行计数,但它在 O(n^2) 中。
我可以使用任何更快的算法或实现吗?
String[] expList = {"i", "i'd", "i'll", "i'm", "i'm", "bet[a-zA-Z]*", "my[a-zA-Z]*"};
String[] textToBeTested = {"this", "is", "better", "than", "my", "method"};
例如在上面的 textToBeTested 数组中,"better" 和 "my" 匹配 expList 数组中的一个字符串,所以它会返回 2。
非常感谢您的帮助。
【问题讨论】:
标签: java regex algorithm arraylist