# 二进制求和

给你两个二进制字符串,返回它们的和(用二进制表示)。

输入为 非空 字符串且只包含数字 1 和 0

 

示例 1:

输入: a = "11", b = "1"
输出:
"100"

示例 2:

输入: a = "1010", b = "1011"
输出:
"10101"

 

提示:

## template ```python class Solution(object): def addBinary(self, a, b): res = '' lsa, lsb = len(a), len(b) pos, plus, curr = -1, 0, 0 while (lsa + pos) >= 0 or (lsb + pos) >= 0: if (lsa + pos) >= 0: curr += int(a[pos]) if (lsb + pos) >= 0: curr += int(b[pos]) res = str(curr % 2) + res curr //= 2 pos -= 1 if curr == 1: res = '1' + res return res # %% s = Solution() print(s.addBinary(a = "1010", b = "1011")) ``` ## 答案 ```python ``` ## 选项 ### A ```python ``` ### B ```python ``` ### C ```python ```