U

7. Reverse Digits and Check Palindrome

Easy

Problem Description

Given a non-negative integer NN, reverse its decimal digits numerically. Print the reversed number on the first line (omitting leading zeros, except when the reversed value is 00). On the second line, print true if the reversed number equals the original number NN (i.e., NN is a palindrome), or false otherwise.

Input Format

A single line containing a non-negative integer NN.

Output Format

  • •Line 1: The reversed integer value.
  • •Line 2: true if NN is a palindrome, else false.
Example 1:
Input:
12321
Output:
12321
true
Explanation: Reversing 12321 yields 12321, which equals the original number.
Example 2:
Input:
1230
Output:
321
false
Explanation: Reversing 1230 yields 321. Since 321 != 1230, it is not a palindrome.
Example 3:
Input:
7
Output:
7
true
Explanation: Single digit numbers are always palindromes.
Constraints:
  • 0 <= N <= 10^15
  • Time complexity target: O(log10 N)
  • Auxiliary space target: O(1)
Follow up:How would you detect integer overflow when reversing signed 32-bit integers?
1,180 Online