LC 9. Palindrome Number

/**
 * @param {number} x
 * @return {boolean}
 */
var isPalindrome = function(x) {
  if (x < 0 || (!(x % 10) && x)) return false
  let x2 = x, res = 0
  while(x2) {
    res = res * 10 + x2 % 10
    x2 = ~~(x2 / 10)
  }
  return res === x
};

~~ 在数字范围为 -2147483649 < value < 2147483648 时,相当于 Math.trunc()

欢迎通过「邮件」或者点击「这里」告诉我你的想法
Welcome to tell me your thoughts via "email" or click "here"