题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool isPalindrome(string str){
for(int i=0,j=str.size()-1;i<j;i++,j--){
if(str[i]!=str[j]){
return false;
}
}
return true;
}
int main() {
string input;
while (cin>>input) {
int max=0;
for(int i=0;i<=input.size()-1;i++){
for(int j=input.size()-i;j>=1;j--){
string temp=input.substr(i,j);
if(isPalindrome(temp)){
if(temp.size()>max){
max=temp.size();
}
}
}
}
cout<<max<<endl;
}
}
// 64 位输出请用 printf("%lld")
