Reverse Integer
easySave
MathNumber Theory
Given a signed 32-bit integer, reverse the digits of the integer. If reversing the integer causes it to go outside the signed 32-bit integer range [-2^31, 2^31 - 1], then return 0.
Example 1
Input
[ 123 ]
Output
321
Explanation. The integer 123 reversed becomes 321.
Example 2
Input
[ -123 ]
Output
-321
Explanation. The integer -123 reversed becomes -321.
Example 3
Input
[ 120 ]
Output
21
Explanation. The integer 120 reversed becomes 21 (removing the leading zero).
Example 4
Input
[ 1534236469 ]
Output
0
Explanation. Reversing 1534236469 exceeds the 32-bit signed integer range, thus the output is 0.
Follow-up: Consider how you would handle numbers that are on the boundary of the 32-bit signed integer range when reversed.
Constraints:
- The input is guaranteed to be a 32-bit signed integer.
- Views
- 4