题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
#include <stdio.h>
#include <string.h>
int isPalindrome(char str[], int begin, int end){
int b = begin;
int e = end;
while (begin < end) {
if (str[begin++] != str[end--]) {
return 0;
}
}
//printf("%d\n", e - b + 1);
return e - b + 1;
}
int main() {
char s[351];
scanf("%s", s);
int maxLen = 0;
int strLen = strlen(s);
//printf("%d\n", strLen);
for(int i = 0; i < strLen - 1; i++){
for (int j = i + 1; j < strLen; j++) {
int len = isPalindrome(s, i, j);
if (maxLen < len) {
maxLen = len;
}
}
}
printf("%d", maxLen);
}