题解 | #密码截取#

密码截取

https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1

#include <iostream>
using namespace std;

int main() {
    string s;
    cin>>s;
    int max_length=1;
    for (int i=1; i<s.size(); i++) {
        int low=i-1,high=i;
        while(low>=0 && high<s.size() && s[low]==s[high]) {
            low--;
            high++;
        }
        max_length=max(max_length,high-low-1);

        low=i-1;
        high=i+1;
        while (low>=0 && high<s.size() && s[low]==s[high]) {
            low--;
            high++;
        }
        max_length=max(max_length,high-low-1);
    }
    cout<<max_length<<endl;
}


// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
03-18 14:29
牛客604067584号:感觉算法卷的人少很多,毕竟只有一部分bg还不错的硕士才会考虑算法,虽然hc不如后端,但是竞争真的少很多。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务