Reverse IntegerMedium

math overflow

Reverse the decimal digits of a signed 32-bit integer x; return 0 if the reversed value falls outside [-2^31, 2^31 - 1]. Two approaches — switch and watch how each handles digits, sign and overflow.

Press play to watch the algorithm run.
Metrics
Legend
How it works
0 / 0