@@ -84,7 +84,7 @@ def longest_common_subsequence(first_sequence: str, second_sequence: str):
84
84
----------
85
85
first_sequence: str
86
86
The first sequence (or string).
87
-
87
+
88
88
second_sequence: str
89
89
The second sequence (or string).
90
90
@@ -107,12 +107,12 @@ def longest_common_subsequence(first_sequence: str, second_sequence: str):
107
107
>>> longest_common_subsequence("abc", "abc")
108
108
(3, 'abc')
109
109
"""
110
- m , n = len (x ), len (y )
110
+ m , n = len (first_sequence ), len (second_sequence )
111
111
dp = [[0 ] * (n + 1 ) for _ in range (m + 1 )]
112
112
113
113
for i in range (1 , m + 1 ):
114
114
for j in range (1 , n + 1 ):
115
- if x [i - 1 ] == y [j - 1 ]:
115
+ if first_sequence [i - 1 ] == second_sequence [j - 1 ]:
116
116
dp [i ][j ] = dp [i - 1 ][j - 1 ] + 1
117
117
else :
118
118
dp [i ][j ] = max (dp [i - 1 ][j ], dp [i ][j - 1 ])
@@ -121,8 +121,8 @@ def longest_common_subsequence(first_sequence: str, second_sequence: str):
121
121
i , j = m , n
122
122
lcs = []
123
123
while i > 0 and j > 0 :
124
- if x [i - 1 ] == y [j - 1 ]:
125
- lcs .append (x [i - 1 ])
124
+ if first_sequence [i - 1 ] == second_sequence [j - 1 ]:
125
+ lcs .append (first_sequence [i - 1 ])
126
126
i -= 1
127
127
j -= 1
128
128
elif dp [i - 1 ][j ] > dp [i ][j - 1 ]:
@@ -133,6 +133,7 @@ def longest_common_subsequence(first_sequence: str, second_sequence: str):
133
133
return dp [m ][n ], "" .join (reversed (lcs ))
134
134
135
135
136
+
136
137
if __name__ == "__main__" :
137
138
import doctest
138
139
0 commit comments