Easy Problems

9. Palindrome Number

What will be learned

  • Understand how to manipulate numbers and check properties.

Solutions

function isPalindrome(x: number): boolean {
  if(x < 0) return false;
 
  if(x % 10 === 0 && x !== 0) return false;
 
  let rev = 0;
  let pop
  while (x > rev) {
      pop = x % 10;
      x = (x - pop) / 10;
      rev = rev * 10 + pop;
  }
 
  return rev === x || Math.floor(rev / 10) === x;
};

Video Solution

Last Update: 12:08 - 16 April 2024
Math

On this page