题目链接https://pintia.cn/problem-sets/1218774283169423360/problems/1218774532776648715
方法一, 见代码
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include<cmath> #include<vector> using namespace std; typedef long long ll; string a; int m = 0; int solve1(int l, int r) { while (l >= 0 && r < a.size() && a[l] == a[r]) { l--;r++; } return r - 1 - (l + 1) + 1; } int solve2(int l, int r) { while (l >= 0 && r < a.size() && a[l] == a[r]) { l--;r++; } return r - 1 - (l + 1) + 1; } int main() { getline(cin, a); for (int i = 0; i < a.size(); i++) { m = max(solve1(i,i), m); m = max(solve2(i,i + 1), m); } cout << m << endl; }
方法二 马拉车算法
原文地址:https://www.cnblogs.com/hulian425/p/12239101.html
时间: 2024-10-11 04:25:37