var isPalindrome = function(x) {
// 小于0或个位是0但是不包括0
if (x < 0 || (x % 10 === 0 && x !== 0)) {
return false;
}
let s = x;
let t = 0;
while(s) {
// 每次取最低位
t = t * 10 + s % 10;
// 每次少一个最低位,直到为0
s = Math.floor(s / 10);
}
return x == t;
};
回文数_前端算法题 3
于 2022-02-08 20:47:51 首次发布