【发布时间】:2017-10-14 18:39:55
【问题描述】:
假设你有一个方法,它接受一个模式和一个完整的字符串......
方法如下:
public int count(String pattern, String input) {
int count = 0;
// How to implement the number of occurrences of the pattern?
}
所以,输入可能是这样的:
String input = "sdbwedfddfbcaeeudhsomeothertestddtfdonemoredfdsatdevdb";
String pattern = "ddt";
int result = count(pattern, input);
迭代和查找“ddt”出现的最有效方法(就复杂性而言)是什么?
【问题讨论】:
标签: java