Open tsungtingdu opened 3 years ago
var longestPalindrome = function(s) {
let n = s.length
for (let k = 0; k < n; k++) {
let right = n - 1 - k;
let left = 0;
while (right < n) {
if (isPalindrome(left, right)) return s.substring(left, right + 1);
left++
right++
}
}
return s;
function isPalindrome(i, j) {
while (i < j) {
if (s[i] !== s[j]) return false
i++
j--
}
return true;
}
};
暴力解 ...
5.02%
57.20%