import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param A string字符串
* @return int整型
*/
public int getLongestPalindrome (String A) {
// write code here
// write code here
// write code here
int ans = 0;
for (int i = 0; i < A.length(); i ++){
ans = Math.max(ans, Math.max(fan(A, i, i), fan(A, i, i + 1)));
}
return ans;
}
private int fan(String str, int being, int end){
while (being >= 0 && end < str.length() && str.charAt(being) == str.charAt(end)){
being--;
end++;
}
return end - being - 1;
}
}
牛客网:NC17 最长回文子串
最新推荐文章于 2024-07-11 23:29:54 发布