Add Binary(bit.iter,recur)
Input:
a = "11", b = "1"
Output:
"100"Input:
a = "1010", b = "1011"
Output:
"10101"class Solution(object):
def addBinary(self, a, b):
"""
:type a: str
:type b: str
:rtype: str
"""
i = len(a)-1
j = len(b)-1
c = 0
res=''
while i>=0 or j>=0:
if i >=0:
c += int(a[i])
i -=1
if j>=0:
c+=int(b[j])
j-=1
res=str(c%2)+res
c = c//2
if c > 0:
res = str(c)+res
return resLast updated