Description

Given two binary strings a and b, return their sum as a binary string. A binary string consists of only 0s and 1s. You should not use any built-in library for binary conversion or big integer support.

Examples

Input:a = "11", b = "1"
Output:"100"
Explanation:

11 + 1 = 100 in binary.

Input:a = "1010", b = "1011"
Output:"10101"
Explanation:

1010 + 1011 = 10101 in binary.

Input:a = "111", b = "111"
Output:"1110"
Explanation:

111 + 111 = 1110 in binary. This demonstrates adding two equal binary numbers where multiple carries propagate: 1+1=10 (carry 1), 1+1+1(carry)=11 (carry 1), 1+1+1(carry)=11, resulting in 1110.

Constraints

  • 1 ≤ a.length, b.length ≤ 10⁴
  • a and b consist only of '0' or '1' characters.
  • Each string does not contain leading zeros except for the zero itself.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!