可能的重复:
String.indexof() 函数调用的成本/复杂性是多少 https://stackoverflow.com/questions/3562919/what-is-the-cost-complexity-of-a-string-indexof-function-call
java indexof(String str) 方法的复杂性是多少?我的意思是有像 KMP 这样的字符串匹配算法,它以线性时间运行。我正在实现一个需要在一个非常大的字符串中搜索大子字符串的系统,所以我可以使用java indexof(String str)方法还是我应该实现KMP。
Java的复杂性执行 http://www.docjar.com/html/api/java/lang/String.java.html of indexOf
is O(m*n)
where n
and m
分别是搜索字符串和模式的长度。
您可以采取的措施来提高复杂性,例如使用博耶-莫尔 http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm算法智能地跳过比较字符串中无法匹配模式的逻辑部分。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)