回文数_前端算法题 3

阅读 44

2022-02-08

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;
};

 

相关推荐

精彩评论(0)

0 0 举报