Skip to content

Commit 8bccd90

Browse files
committed
fix列表x截取错误
1 parent 7f4bd39 commit 8bccd90

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

string.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
#coding:utf-8
23
import numpy as np
34

@@ -51,11 +52,11 @@ def LCS_recursive(x,y):
5152
if x[-1]==y[-1]:
5253
return LCS_recursive(x[:-1],y[:-1])+x[-1]
5354
else:
54-
return max_str(LCS_recursive(x[:-1],y[-1]),LCS_recursive(x[:],y[:-1]))
55+
return max_str(LCS_recursive(x[:-1],y[:]),LCS_recursive(x[:],y[:-1]))
5556

5657
str1 = 'BCDABAB'
5758
str2 = 'CBAABAABA'
58-
#print LCS_recursive(str1,str2)
59+
print LCS_recursive(str1,str2)
5960
#CABAB
6061

6162
def max_int(a,b):
@@ -75,7 +76,7 @@ def LCS_dynamic(x,y):
7576
line.append(0)
7677

7778
for i in range(x_len+1):
78-
matrix.append(line[:])
79+
matrix.append(line[:])#浅拷贝害死人
7980
#print len(matrix),len(matrix[0])
8081
#矩阵零行零列填充完毕,填充矩阵剩余部分,矩阵从0行开始,矩阵第i行对应x[i-1]
8182
for i in range(1,x_len+1):

0 commit comments

Comments
 (0)