Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite006f31

Browse files
update
1 parenteeb69c1 commite006f31

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

‎AwesomeAlgorithms/KMP算法.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,20 @@ def matchTable(aList):
3838
else:
3939
index+=1
4040
returntable
41+
# 更具有一般性的字符移动表
42+
defmatchTable2(aList):
43+
length=len(aList)
44+
table= [0]*length
45+
index=1
46+
whileindex<length:
47+
sameLen=0
48+
whileindex+sameLen<lengthandaList[sameLen]==aList[index+sameLen]:
49+
sameLen+=1
50+
table[index+sameLen-1]=sameLen
51+
ifsameLen!=0:
52+
index+=sameLen
53+
else:
54+
index+=1
55+
returntable
4156

42-
print(kmp('aaaaa','aa'))
57+
print(kmp('aaaaa','aa'))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp