AlgoLounge

Reverse Integer

medium

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.

Assume the environment does not allow you to store 64-bit integers (signed or unsigned).

Examples

Example 1

Input:  x = 123
Output: 321

Example 2

Input:  x = -123
Output: -321

Example 3

Input:  x = 120
Output: 21

Constraints

  • -2³¹ <= x <= 2³¹ - 1
TypeScript
Loading editor…
List of test cases (8)
Case 1
x = 123
Case 2
x = -123
Case 3
x = 120
Case 4
x = 0
Case 5
x = 1534236469
Case 6
x = -2147483648
Case 7
x = 1463847412
Case 8
x = -100