题目描述:
解法一:字符串反转法
var isPalindrome = function(x) {
return x === Number(x.toString().split('').reverse().join(''));
};
解法二:二分对比法
var isPalindrome = function(x) {
var strX = x.toString();
var xLength = strX.length;
for (let i = 0; i < Math.floor(xLength / 2); i++) {
if ( strX[i] !== strX[xLength - i - 1]) {
return false;
}
}
return true;
};
解法三:双指针法
var isPalindrome = function(x) {
let strX = x.toString();
let left = 0;
let right = str.length - 1;
while(left < right){
if(str[left++] !== str[right--]){
return false;
}
}
return true;
}