574. Reverse a Number Using Stack

EasyStackStackMath

Given a non-negative integer n, return the number formed by reversing its digits (leading zeros are dropped naturally). Conceptually, push each digit onto a stack and pop them to build the reversed number. The input is JSON {n}.

Input: JSON {n}.

Output: Integer — the digits of n reversed.

Examples

Example 1
Input: {"n":123}
Output: 321
Explanation: Digits reversed.
Example 2
Input: {"n":120}
Output: 21
Explanation: Trailing zero becomes leading and is dropped.
Example 3
Input: {"n":0}
Output: 0
Explanation: Zero reversed is zero.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →