Binary Representation of a Number
EasyP3Coding
Given a non-negative integer n, return its binary representation as a string with no leading zeros. For n = 0 return "0".
Do not use a built-in base conversion such as toString(2) or bin().
Example 1
- Input
- n = 10
- Output
- "1010"
Example 2
- Input
- n = 0
- Output
- "0"
Example 3
- Input
- n = 1
- Output
- "1"
Constraints
- 0 <= n <= 2^31 - 1
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.