Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Reverse Integer
Bookmark
Input
Example 1
Negative
Trailing Zero
Overflow
Custom
x
=
123
x
1
2
3
Peel the last digit of x onto result
x
1
2
3
Peel the last digit of x onto result
x
1
2
3
digit = 123 % 10 =
3
x
1
2
3
0
within 32-bit range ✓
x
1
2
3
result
3
x =
12
≠ 0
x
1
2
3
result
3
x = 12 / 10 =
1
x
1
2
3
result
3
3
within 32-bit range ✓
x
1
2
3
result
3
2
x =
1
≠ 0
x
1
2
3
result
3
2
x = 1 / 10 =
0
x
1
2
3
result
3
2
1
result = 32 × 10 + 1 =
321
x
1
2
3
result
3
2
1
x = 0, all digits consumed
reverse(123) = 321
algo
master
.
io
Step:
Start: reverse the integer 123
0 / 17
Input
Example 1
Negative
Trailing Zero
Overflow
Custom
x
=
123
0 / 17
algo
master
.
io
Step:
Start: reverse the integer 123