假设有以下字符串:
string a = "abc"
string b = "abcdcabaabccbaa"
在 b 中找到所有 a 的排列位置。我正在尝试找到一个有效的算法。
伪代码:
sort string a // O(a loga)
for windows of length a in b // O(b)?
sort that window of b // O(~a loga)?
compare to a
if equal
save the index
这个算法是否正确?运行时间大约为O(aloga + ba loga) ~= O(a loga b)。这有多有效率?可能有一种方法可以将其简化为O(a * b) 或更好的复杂度?
O(n+s)
... - md5