Decimal to Binary
Given a non-negative decimal integer n, return its binary representation as a string containing only 0 and 1. The binary representation must contain no…
Given a non-negative decimal integer `n`, return its binary representation as a string containing only `0` and `1`. The binary representation must contain no leading zeroes, except that the value `0` is represented by the string `"0"`.
- `0 <= n <= 10^9` - Return the representation as a string. - Do not include a base prefix such as `0b`.
Example 1: input n = 13; output "1101". 13 equals 8 + 4 + 1, so its binary digits are 1101.
Example 2: input n = 16; output "10000". Sixteen is a power of two, so its representation is one followed by four zeroes.
Example 3: input n = 0; output "0". Zero uses the single binary digit 0.
Category: Math. Topic: math. Difficulty: Easy. Patterns: math.