题解 | #最长回文子串#
最长回文子串
http://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af
遍历解法
class Solution {
public:
inline int numMax(int a,int b){
return a>b ? a : b;
}
int getLongestPalindrome(string A, int n) {
// write code here
int ans=1, strLength = A.size();
for(int i=0;i<strLength;i++){
for(int j=i+1; j<strLength;j++){
if(A[i]==A[j]){
for(int a=i,b=j;a<=b&&A[a]==A[b];a++,b--){
if(b-a<2){
ans = numMax(ans,j-i+1);
}
}
}
}
}
return ans;
}
}; 
