600. Convert Decimal to Binary Using Stack

EasyStackStackMath

Given a non-negative integer n, return its binary representation as a string (without leading zeros; 0 maps to "0"). A stack collects the remainders of repeated division by 2. The input is JSON {n}.

Input: JSON {n}.

Output: String — the binary representation.

Examples

Example 1
Input: {"n":10}
Output: 1010
Explanation: 10 in binary.
Example 2
Input: {"n":0}
Output: 0
Explanation: Zero.
Example 3
Input: {"n":255}
Output: 11111111
Explanation: Eight ones.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →