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

}

你可能感兴趣的:(LeetCode)