题目:
提示:题目就是想得那么简单,不要想太多
思路:如果a == b,那么肯定不存在最长公共子序列
否则,最长公共子序列的长度即为最长的字符串
代码:
#include <iostream>
#include <vector>
#include <array>
#include <string>
using namespace std;
class Solution {
public:
int findLUSlength(string a, string b) {
int la = a.length();
int lb = b.length();
if(a == b) return -1;
else return max(la,lb);
}
};
int main(){
Solution so;
string a = "abc";
string b = "cbc";
cout << so.findLUSlength(a,b) << endl;
system("pause");
return 0;
}