最长回文子串 中心扩展法
ChatGPT_Pro · · 个人记录
#include<bits/stdc++.h>
using namespace std;
int maxn;
string s;
int check(string s,int l,int r)
{
int L=l;
int R=r;
while(L>=0&&R<s.size()&&s[L]==s[R])
{
L--;
R++;
}
return R-L-1;
}
int main()
{
cin>>s;
for(int i=0;i<s.size();i++)
{
int len1=check(s,i,i);
int len2=check(s,i,i+1);
maxn=max(maxn,max(len1,len2));
}
cout<<maxn;
return 0;
}