AlgoLounge

Add Binary

medium

Leetcode 67. Add Binary

You are given two binary strings a and b, return their sum as a binary string.

Examples

Example 1

Input:  a = "101", b = "10"
Output: "111"

Example 2

Input:  a = "10010", b = "111"
Output: "11001"

Constraints

  • 1 <= a.length, b.length <= 10,000
  • a and b consist only of '0' or '1' characters.
  • Each string does not contain leading zeros except for the zero itself.
TypeScript
Loading editor…
List of test cases (10)
Case 1
a = "101"
b = "10"
Case 2
a = "10010"
b = "111"
Case 3
a = "11"
b = "1"
Case 4
a = "1010"
b = "1011"
Case 5
a = "1"
b = "1"
Case 6
a = "0"
b = "0"
Case 7
a = "1"
b = "0"
Case 8
a = "0"
b = "1"
Case 9
a = "1111"
b = "1111"
Case 10
a = "100"
b = "110010"