Skip to content

Commit 773f5a3

Browse files
authored
Update longest-common-subsequence.cpp
1 parent 80d9f2b commit 773f5a3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

C++/longest-common-subsequence.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
class Solution {
55
public:
66
int longestCommonSubsequence(string text1, string text2) {
7-
if (text1.size() < text2.size()) {
7+
if (text1.length() < text2.length()) {
88
return longestCommonSubsequence(text2, text1);
99
}
10-
vector<vector<int>> dp(2, vector<int>(text2.size() + 1));
11-
for (int i = 1; i <= text1.size(); ++i) {
12-
for (int j = 1; j <= text2.size(); ++j) {
10+
vector<vector<int>> dp(2, vector<int>(text2.length() + 1));
11+
for (int i = 1; i <= text1.length(); ++i) {
12+
for (int j = 1; j <= text2.length(); ++j) {
1313
dp[i % 2][j] = (text1[i - 1] == text2[j - 1])
1414
? dp[(i - 1) % 2][j - 1] + 1
1515
: max(dp[(i - 1) % 2][j], dp[i % 2][j - 1]);
1616

1717
}
1818
}
19-
return dp[text1.size() % 2][text2.size()];
19+
return dp[text1.length() % 2][text2.length()];
2020
}
2121
};

0 commit comments

Comments
 (0)