leetcode #9 Palindrome Number

2017-07-06  本文已影响0人  huntriver

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

没有什么好说得,循环判断首尾是否相同即可

/**
 * @param {number} x
 * @return {boolean}
 */
var isPalindrome = function (x) {
    let s = String(x);
    let len = s.length;
    for (let i = 0; i < len / 2; i++) {
        if (s[i] != s[len - i - 1]) {
            return false;
        }
    }
    return true;
};
上一篇下一篇

猜你喜欢

热点阅读