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^31, 2^31 - 1], then return 0. Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
Example 1
Input: x = 123
Output: 321
Explanation: Reading the digits of 123 backwards gives 321, which fits in a 32-bit integer.
Example 2
Input: x = -123
Output: -321
Explanation: The digits reverse to 321 and the minus sign is kept, giving -321.
Example 3
Input: x = 120
Output: 21
Explanation: Reversing 120 gives 021, and the leading zero is dropped, leaving 21.
Peel the last digit off x with % 10 and append it to the result with * 10. Before each append, check whether the multiply would overflow the 32-bit range and bail out with 0 if so.
Run checks all cases above. Submit evaluates all test cases.