"""
QUESTION:
Given two binary strings, return their sum (also a binary string).

For example,
a = "11"
b = "1"
Return "100".
ANSWER:
counting and tracking
"""

class Solution(object):
    def addBinary(self, a, b):
        """
        :type a: str
        :type b: str
        :rtype: str
        """
        i = 0
        carry = 0
        s = ''
        while i < len(a) or i < len(b) or carry > 0:
            c = carry
            if i < len(a):
                c += int(a[-1-i])
            if i < len(b):
                c += int(b[-1-i])
            carry = c/2
            c = c%2
            s = str(c) + s
            i += 1
        return s

if __name__ == '__main__':
    print Solution().addBinary('111','10100')