Easy · Math

Reverse number

Given a signed 64-bit integer n, reverse its decimal digits while keeping its sign. Leading zeros of the reversal disappear (1200 → 21 and −507 → −705). Return 0 if the reversed value does not fit in a signed 64-bit integer.

Examples

Example 1

n = 1234

Output: 4321

Example 2

n = -507

Output: -705

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Math problems