Easy
Reverse an Integer
- Time limit
- 1 s
- Memory limit
- 128 MB
- Estimated
- 15 min
- Programming Fundamentals
Description
Given a non-negative integer n, return the integer formed by reversing the order of its decimal digits.
The reversal must be performed numerically. If the original number ends with zeroes, those zeroes become leading zeroes after reversal and must be omitted from the resulting integer.
For example, reversing 4821 produces 1284. Reversing 1200 produces 21, not 0021. Reversing 0 produces 0.
Implement the function reverseInteger(n) that returns the reversed integer.
Constraints
0 <= n <= 2147483647 The reversed result fits within a signed 64-bit integer.
Sample cases
3Sample 1
Input
n = 4821
Expected output
1284
Sample 2
Input
n = 1200
Expected output
21
Sample 3
Skills and languages
Concepts
- Control Flow and Data Types
- Number Bases and Digit Manipulation
Languages
- Python 3
Solve this problem
Create a free account to write, run and submit your solution.
- Write Python or Java in the browser, with your draft saved as you type
- Run your code on the examples as often as you like
- Submit to a sandboxed judge and see exactly which case failed
- Ask the AI mentor for a hint without being handed the answer