Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Reverse Digits of a Number

Basic Acceptance 89.81% Points 10.00

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.

Examples
Example 1

Input: n = 1234
Output: 4321
Explanation: Reversing the digits of 1234 produces 4321.

Example 2

Input: n = 120
Output: 21
Explanation: Reversing 120 gives 021, which is represented as 21.

Example 3

Input: n = 5
Output: 5
Explanation: A single-digit number remains unchanged when its digits are reversed.

Constraints
  • 0 = n = 10?
Companies
Apple Walmart
Topics
Data Structures Basics
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions