|
U
Pro7. Reverse Digits and Check Palindrome
Easy
Problem Description
Given a non-negative integer N, reverse its decimal digits numerically. Print the reversed number on the first line (omitting leading zeros, except when the reversed value is 0). On the second line, print true if the reversed number equals the original number N (i.e., N is a palindrome), or false otherwise.
Input Format
A single line containing a non-negative integer N.
Output Format
- •Line 1: The reversed integer value.
- •Line 2:
trueif N is a palindrome, elsefalse.
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^15Time 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
Code
|Loading Code Editor...
SavedLn 1, Col 1
input =
Sandboxed Engine
Ctrl+Enter = Run | Ctrl+Shift+Enter = Submit