Reverse Integer
easySave
MathNumber Theory
Given an integer, reverse the digits of the integer. The reversed integer should not have any leading zeros unless the original integer is zero.
Example 1
Input
[ 123 ]
Output
321
Explanation. Reversing the digits of 123 results in 321.
Example 2
Input
[ -123 ]
Output
-321
Explanation. Reversing the digits of -123 results in -321, maintaining the negative sign.
Example 3
Input
[ 1200 ]
Output
21
Explanation. Reversing 1200 results in 0021, which should be represented without leading zeros as 21.
Example 4
Input
[ 0 ]
Output
0
Explanation. Reversing 0 still yields 0.
Follow-up: Can you solve this problem without converting the integer to a string?
Constraints:
- The given integer will fit in a standard 32-bit signed integer range.\n- Ensure you manage negative integers appropriately, retaining the negative sign at the front when reversed.
- Views
- 3