Problem
Given a signed 32-bit integer x, return it with its decimal digits reversed, keeping the sign. If the reversed value falls outside the signed 32-bit range [-2^31, 2^31 - 1], return 0.
Example 1
- Input
- x = 123
- Output
- 321
Example 2
- Input
- x = -123
- Output
- -321
Example 3
- Input
- x = 120
- Output
- 21
- Why
- the trailing zero becomes a leading zero and disappears
Example 4
- Input
- x = 1534236469
- Output
- 0
- Why
- 9646324351 does not fit
Constraints
-2^31 <= x <= 2^31 - 1Assume you cannot store a 64-bit integer: detect overflow before it happens.