Add Binary
EasyP2Coding
Given two binary strings a and b, return their sum as a binary string.
The inputs have no leading zeros except for the string "0" itself, and the result must follow the same rule.
Example 1
- Input
- a = "11", b = "1"
- Output
- "100"
Example 2
- Input
- a = "1010", b = "1011"
- Output
- "10101"
Example 3
- Input
- a = "0", b = "0"
- Output
- "0"
Constraints
- 1 <= a.length, b.length <= 10^4
- a and b contain only "0" and "1"
- No leading zeros except for the string "0"
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.