<jupyter_start><jupyter_text>描述：    给定两个二进制字符串，返回它们的总和（也是一个二进制字符串）。输入字符串均为非空，并且仅包含字符1或0。Example 1:    Input: a = "11", b = "1"    Output: "100"Example 2:    Input: a = "1010", b = "1011"    Output: "10101"约束：1、每个字符串仅包含“ 0”或“ 1”字符。 2、1 <= a.length，b.length <= 10 ^ 4每个字符串要么为“ 0”，要么不包含任何前导零。<jupyter_code>class Solution:
    def addBinary(self, a: str, b: str) -> str:
        # 实现二进制字符串的相加
        a = a[::-1]
        b = b[::-1]
        if len(a) < len(b):
            a, b = b, a
        
        rets = [int(i) for i in a]
        for i, b_ in enumerate(b):
            if rets[i] == 2:
                rets = self.helper(i, rets)     
            rets[i] += int(b_)
            if rets[i] == 2:
                rets = self.helper(i, rets)
        
        for i, ret in enumerate(rets):
            if ret == 2:
                rets = self.helper(i, rets)
        rets.reverse()
        rets = [str(i) for i in rets]
        return ''.join(rets)
    
            
    def helper(self, i, nums):
        nums[i] = 0
        if i + 1 <= len(nums) - 1:
            nums[i + 1] += 1
        else:
            nums.append(1)
        return nums
a_ = '1111'
b_ = '1111'
solution = Solution()
solution.addBinary(a_, b_)
a = '11'
str(reversed(a))
a.reverse()
a
a = ['1', '2']
''.join(a)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16247139588100687, 'fraction_numerical': 0.041952707856598014, 'mean_word_length': 1.7276507276507276, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '543180', 'license': 'Apache-2.0', 'n_tokens_mistral': 612, 'n_tokens_neox': 597, 'n_words': 125, 'path': 'String/0821/67. Add Binary.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '1311'}