cheetcode

150. Reverse IntegerMedium

Reverse the digits of a signed 32-bit integer while respecting overflow limits.

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, return 0.

Examples

Input: x = 123
Output: 321
Input: x = -123
Output: -321

Constraints

  • -2^31 <= x <= 2^31 - 1