File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 4
4
class Solution {
5
5
public:
6
6
int longestCommonSubsequence (string text1, string text2) {
7
- if (text1.size () < text2.size ()) {
7
+ if (text1.length () < text2.length ()) {
8
8
return longestCommonSubsequence (text2, text1);
9
9
}
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) {
13
13
dp[i % 2 ][j] = (text1[i - 1 ] == text2[j - 1 ])
14
14
? dp[(i - 1 ) % 2 ][j - 1 ] + 1
15
15
: max (dp[(i - 1 ) % 2 ][j], dp[i % 2 ][j - 1 ]);
16
16
17
17
}
18
18
}
19
- return dp[text1.size () % 2 ][text2.size ()];
19
+ return dp[text1.length () % 2 ][text2.length ()];
20
20
}
21
21
};
You can’t perform that action at this time.
0 commit comments