Add Two Binary Strings
Problem statement
Given two nonempty binary strings a and b, return their sum as a binary string. Each input contains only 0 and 1 and represents a nonnegative integer.
For this exercise, assume inputs may contain leading zeros. The returned representation must have no leading zeros unless the sum is zero, in which case return 0. The strings may be too long for built-in fixed-width integers.
Function
addBinaryStrings(a: String, b: String) → StringExamples
Example 1
a = "1011"b = "1101"return = "11000"The inputs represent 11 and 13; their sum 24 is binary 11000.
Example 2
a = "000"b = "0"return = "0"The sum is zero, whose normalized representation is a single 0.
Constraints
- For this exercise, assume
1 <= a.length, b.length <= 10^5. - Every character is
0or1. - Return the full exact binary sum.