Leetcode 9 Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.

利用余数构造倒置数再判断。

var isPalindrome = function(x) {
    var y = 0
    var t = x
    while(t > 0){
        y = y*10 + t%10
        t = Math.floor(t/10)
    }
    if (x===y)
        return true
    else
        return false
}
posted @ 2015-06-20 23:11  lilixu  阅读(112)  评论(0编辑  收藏  举报