Skip to content
Onsite

Reverse a Number

EasyP2Coding

Reverse the decimal digits of a non-negative integer using recursion and return the new number.

Trailing zeros of the input become leading zeros and disappear, so 1200 becomes 21.

Example 1

Input
n = 123
Output
321
Why
The digits 1, 2, 3 reversed are 3, 2, 1.

Example 2

Input
n = 1200
Output
21
Why
1200 reversed digit by digit is 0021, which is 21.

Example 3

Input
n = 0
Output
0

Constraints

  • 0 <= n <= 10^9

Hints

Run checks the 3 visible tests, Submit all 9.