Add Binary
Easy · bit manipulation
Two meters each display a number in binary, written as a string of the characters "0" and "1".
Given the strings a and b, return their sum, also written in binary as a string.
The inputs have no leading zeros (except for the number zero itself, which is written "0"), and the answer must follow the same rule.
Examples
Example 1
Input: a = "11", b = "1"
Output: "100"
3 + 1 = 4, which is 100 in binary.
Example 2
Input: a = "1010", b = "1011"
Output: "10101"
10 + 11 = 21, which is 10101 in binary.
Example 3
Input: a = "0", b = "0"
Output: "0"
Constraints
- 1 <= len(a), len(b) <= 10^4
- a and b contain only the characters '0' and '1'.
- Neither string has a leading zero, unless the string is exactly "0".