LC 9. Palindrome Number
1/**
2 * @param {number} x
3 * @return {boolean}
4 */
5var isPalindrome = function(x) {
6 if (x < 0 || (!(x % 10) && x)) return false
7 let x2 = x, res = 0
8 while(x2) {
9 res = res * 10 + x2 % 10
10 x2 = ~~(x2 / 10)
11 }
12 return res === x
13};
~~
在数字范围为 -2147483649 < value < 2147483648 时,相当于 Math.trunc()。