题解 | #最长回文子串#

最长回文子串

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

//https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507?tpId=37&tqId=21308&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26pageSize%3D50%26search%3D85%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=85

#include <iostream>
#include <algorithm>

using namespace std;

int maxlength(string s, int l, int r){
    while(l>=0&&r<s.size()&&s[l]==s[r]){
        l--;
        r++;
    }
    return r-l-1;
}

int main() {
    string s;
    int maxn = 0;

    while(cin >> s){
        for(int i = 0;i<s.size();i++)
            maxn = max(maxn, max(maxlength(s, i, i), maxlength(s, i, i+1)));

        cout << maxn <<endl;
    }

}

全部评论

相关推荐

05-12 22:16
已编辑
北京邮电大学 研发工程师
牛客302360988号:0offer+1 滴滴都不给我面 佬没投鹅吗,鹅应该很喜欢北邮吧
投递美团等公司7个岗位
点赞 评论 收藏
分享
爱吃肉的伊登在写日记:好棒,27届简历能做成这个样子,但是第一个项目感觉cover住难度还是不小的,特别是二面的时候肯定要对分布式系统设计这一块儿有高出正常面试者的水平才行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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