225. Decimal to Binary
Foundation1000 ms256 MBSolved by 0%
Print the binary representation of n, with no leading zeros.
Dividing by 2 gives you the digits, and n % 2 gives you each one, but they
come out backwards: the first remainder you get is the LAST binary digit.
Recursion handles that neatly. Print the result for n / 2 first, then print
the current remainder. The reversal happens for free because the deeper calls
finish first.
Constraints - `0 ≤ n ≤ 1000000000`
Input
A single line containing one integer n.
Output
Print the binary form of n on one line, with no leading zeros.
Input5
Output101
Noteis a small value with a mixed pattern
Input0
Output0
Notemust print a single 0, not an empty line
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution