Given a non-negative integer n, return the number you get when you write its digits in reverse order.
Zeros at the end of n move to the front of the reversed number, where they don't count: 120 reversed is 21. If n is 0, the answer is 0.
Example 1:
Input: n = 123 Output: 321 Explanation: The digits 1, 2, 3 read backwards are 3, 2, 1.
Example 2:
Input: n = 120 Output: 21 Explanation: Backwards the digits are 0, 2, 1, and 021 is the number 21.
Example 3:
Input: n = 7 Output: 7 Explanation: A number with one digit stays the same.
Constraints:
0 <= n <= 109
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
