
Reverse Integer (medium)
Problem Statement
Given a signed 32-bit integer x, return the reverse of x. If the reversed value of x goes beyond the signed 32-bit integer range [-2<sup>31</sup>, 2<sup>31</sup> - 1], then return 0.
A reverse of x should not contain leading zeros.
Examples
-
Example 1:
- Input: x =
123 - Expected Output:
321 - Justification: Reversing the digits of 123 results in 321, which is within the 32-bit signed integer range.
- Input: x =
-
Example 2:
- Input: x =
-456432 - Expected Output:
-234654 - Justification: Reversing the digits of -456432 results in -234654, maintaining the negative sign and staying within the 32-bit signed integer range.
- Input: x =
-
Example 3:
- Input: x =
1200 - Expected Output:
21 - Justification: Reversing the digits of 1200 results in 0021, but leading zeros are dropped, resulting in 21.
- Input: x =
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory