Tod's problem is checking whether the number is a palindrome. I think the problem is clear and straightforward, but just for reference purposes, I will put some scenarios hereunder. BTW, you can find the description here.

Example 1:

Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.

Example 2:

Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-.
Therefore it is not a palindrome.

Example 3:

Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.

My Solution

My intuition is simple. First, check if a number is a negative number and if the number is negative, return false since there is no reverse for it.

When the number is greater than zero, there are steps. Here are the steps:

  1. Create a variable to hold the copy of the number
  2. Create a remainder variable and initialize it by zero
  3. Perform a division of the number by 10
  4. Multiply the remainder by 10 and add the remainder of the above division
  5. Update the number by the integer part of the above division
  6. Keep on performing the above three steps until the number becomes zero
  7. Then check if the value of the remaining variable equals the copy of the number

Results

Runtime: 66 ms, faster than 91.10% of Python3 online submissions for Palindrome Number.

Memory Usage: 14 MB, less than 59.42% of Python3 online submissions for Palindrome Number.

I Am excited and waiting for the next challenge.