You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**
* @param {string} s
* @return {string}
*/
var longestPalindrome = function(s) {
let res = "";
for(let i = 0; i < s.length; i++){
// 当i为奇数的中心时
let left = i - 1, right = i + 1;
while(left >= 0 && right < s.length && s[left] == s[right]){
left--;
right++;
}
if(res.length < right - left - 1){
res = s.substr(left + 1, right - left - 1);
}
// 当i为偶数的中心时
left = i, right = i + 1;
while(left >= 0 && right < s.length && s[left] == s[right]){
left--;
right++;
}
if(res.length < right - left - 1){
res = s.substr(left + 1, right - left - 1);
}
}
return res;
};
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: