题解 | #最长回文子串#

最长回文子串

https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507

#include <bits/stdc++.h>
using namespace std;

int main(){
    string str;
    getline(cin,str);
    int x = 0;
    for(int i = 0;i<str.length()-2;i++){
        for(int j = str.length();j>i;j--){
            int n = j-i;
            string str1 = str.substr(i,n);
            string str2 = str1;
            reverse(str2.begin(),str2.end());
            if( str1 == str2 ) {
                x=max(x,n);
            }
        }
    }cout << x;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-07 14:00
点赞 评论 收藏
分享
我是没经验的毕业生,这啥情况啊会不会是hr在刷kpi
JamesGosli...:字节boss属于是群发了,我都快入职字节了,其他部门还在和我boss打招呼
点赞 评论 收藏
分享
缒梦&独舞:这家公司是这样的,去年给我实习offer了,不过也是面着玩儿的,他周六还要去做公益志愿活动
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 13:15
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务