Reverse Integer

Medium

Topics
Math

Given a signed 32-bit integer x, return x with its digits reversed. If reversing causes the value to fall outside the 32-bit signed range [-2^31, 2^31 - 1], return 0.

Example 1

Input:  x = 123
Output: 321

Example 2

Input:  x = -123
Output: -321

Example 3

Input:  x = 120
Output: 21

Constraints

  • -2^31 <= x <= 2^31 - 1
Run ⌘' · Submit ⌘⏎