中国彻底绞杀盗版音乐!220多万首下线# PDA - 掌中宝
T*7
1 楼
class Solution {
public:
string longestPalindrome(string s) {
int maxlen = 0;
string ret;
int st,end = 0;
for(int i = 0; i < s.size(); i ++){
int lena = expandPalin(s, i,i,s.size());
int lenb = expandPalin(s,i,i+1,s.size());
int len = max(lena,lenb);
if(len > maxlen)
{
st = i-(len-1)/2;
end = i+len/2;
maxlen = len;
}
}
return s.substr(st, end-st+1);
}
int expandPalin(string s, int i, int j, int len){
int L=i;
int R = j;
if( L >=0 && R< len && s[L]==s[R]) {
L--;
R++;
}
return R-L-1;
}
};
那個低級錯誤 改正,還是不對
public:
string longestPalindrome(string s) {
int maxlen = 0;
string ret;
int st,end = 0;
for(int i = 0; i < s.size(); i ++){
int lena = expandPalin(s, i,i,s.size());
int lenb = expandPalin(s,i,i+1,s.size());
int len = max(lena,lenb);
if(len > maxlen)
{
st = i-(len-1)/2;
end = i+len/2;
maxlen = len;
}
}
return s.substr(st, end-st+1);
}
int expandPalin(string s, int i, int j, int len){
int L=i;
int R = j;
if( L >=0 && R< len && s[L]==s[R]) {
L--;
R++;
}
return R-L-1;
}
};
那個低級錯誤 改正,還是不對