#!/bin/python3

#67. Given two binary strings, return their sum (also a binary string). 


class Solution(object):
	def addBinary(self, a, b):
		
		result = [0] * (1+max(len(a), len(b))) #One bigger than max
		padding = len(a) - len(b)

		if padding>0: #B is smaller, it needs padding
			b = '0'*padding + b
		else:
			a = '0'*(-1 *padding) + a
		
		#print(a, b)
		for i in reversed(range(0, len(a))):
				result[i+1] += int(a[i]) + int(b[i])
				#print(result)
				if result[i+1]==2:
					result[i], result[i+1] = result[i]+1, 0
				elif result[i+1]==3:
					result[i], result[i+1] = result[i]+1, 1

		if result[0] == 0:
			del result[0]

		ans = ''.join(map(str, result))		
		return ans
	

def main():

	print ("add binary")
	sol = Solution()
	a = '1011'
	b = '1011'

	result = sol.addBinary(a, b)

	print(result)

if __name__=="__main__":main()
