Description
Solutions
Reverse an Integer
🤘 INTERN

Rever an integer (positive or negative) without turning the integer to a sring or using string manipulation 💪

Function Description

Complete the function reverse in the editor.

reverse has the following parameter:

  1. int x: the integer to reverse

(˶˃⤙˂˶) Thanks a TON, Rachel 💖

Example 1:

Input:  x = 123
Output: 321
Explanation:

The reversed integer is 321. Since the reversed integer is within the signed 32-bit integer range, it is the return value.

Example 2:

Input:  x = 120
Output: 21
Explanation:

The reversed integer is 21. Notice that the leading zero in the input integer is not present in the reversed integer.

Example 3:

Input:  x = -120
Output: -21
Explanation:

The reversed integer is -21. The negative sign is preserved during the reversal.

Constraints:
    • -2^31 <= x <= 2^31 - 1
Thumbnail 0
Testcase

Result
Case 1

input:

output: