Given two binary strings, return their sum (also a binary string). The input strings are both non-empty and contains only characters1or 0.
Example 1:
Input: a = "11", b = "1"
Output: "100"
Example 2:
Input: a = "1010", b = "1011"
Output: "10101"
Solution 1: loop from right to left iteratively
defaddBinary(a,b):""" :type a: str :type b: str :rtype: str """ m =len(a)-1 n =len(b)-1 ret ='' count =0while m >=0or n >=0:if m <0: temp =int(b[n])+ countelif n <0: temp =int(a[m])+ countelse: temp =int(a[m])+int(b[n])+ countif temp >=2: ret =str(temp -2)+ ret count =1else: ret =str(temp)+ ret count =0 m -=1 n -=1if count ==1: ret =str(count)+ retreturn ret