Problem · Math

Reverse an Integer

EasyMicrosoftINTERNOA
See Microsoft hiring insights

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 💖

Examples
01 · Example 1
x = 123
return = 321

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

02 · Example 2
x = 120
return = 21

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

03 · Example 3
x = -120
return = -21

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

Constraints
  • -2^31 <= x <= 2^31 - 1
More Microsoft problems
drafts saved locally
public int reverse(int x) {
  // write your code here
}
x123
expected321
sign in to submit