You are given a non-negative integer n. Using only arithmetic operations, your task is to return the number formed by reversing its digits.
The reversed number should not contain unnecessary leading zeros. For example, reversing 120 produces 21, not 021.
Input: n = 1234
Output: 4321
Explanation: Reversing the digits of 1234 produces 4321.
Input: n = 120
Output: 21
Explanation: Reversing 120 gives 021, which is represented as 21.
Input: n = 5
Output: 5
Explanation: A single-digit number remains unchanged when its digits are reversed.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
123
321
4567
7654