朴素匹配可以换成KMP算法,这样的话,时间复杂度能达到线性
主要考虑是建立新的链表子串替换原链表中间的匹配项。不多说了,直接上代码
class
Node
:
def
__init__
(
self
,
element
=
None
,
next_
=
None
,
prev
=
None
):
self
._element
=
element
self
._next
=
next_
self
._prev
=
prev
class
StrList
:
def
__init__
(
self
,
string1
):
self
._head
=
None
self
._rear
=
None
self
._len
=
0
i
=
0
n
=
len
(string1)
while
i
<
n:
if
self
._head
is
None
: