[LeetCode][JavaScript]Palindrome Number
Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.
https://leetcode.com/problems/palindrome-number/
判断一个数字是否为回文,OJ认为负数都不是回文。
倒转这个数字与原始的数字做比较。
1 /** 2 * @param {number} x 3 * @return {boolean} 4 */ 5 var isPalindrome = function(x) { 6 if(x < 0) return false; 7 var origin = x, reverse = 0; 8 while(x > 0){ 9 reverse *= 10; 10 reverse += x % 10; 11 x = Math.floor(x / 10); 12 } 13 return origin === reverse; 14 };