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 = 123
Output:321
Explanation:

The digits of 123 reversed is 321.

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

The negative sign stays, digits reversed.

Input:x = 120
Output:21
Explanation:

Trailing zeros are removed when reversed.

Input:x = 0
Output:0
Explanation:

Zero reversed is still zero.

Constraints

  • -2³¹ ≤ x ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!