Description
Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-2³¹, 2³¹ - 1], then return 0.
Examples
Input:
x = 123Output:
321Explanation:
The digits of 123 reversed is 321.
Input:
x = -123Output:
-321Explanation:
The negative sign stays, digits reversed.
Input:
x = 120Output:
21Explanation:
Trailing zeros are removed when reversed.
Input:
x = 0Output:
0Explanation:
Zero reversed is still zero.
Constraints
- •
-2³¹ ≤ x ≤ 2³¹ - 1