My python solution , waiting for improve.......^_^


  • 0
    B
    class Solution:
        # @param a, a string
        # @param b, a string
        # @return a string
        def addBinary(self, a, b):
            grade=0
            sum=''
            x=list(a)
            y=list(b)
            while len(x)!=0 or len(y)!=0:
                i=0
                j=0
                if len(x)!=0:
                    i=int(x.pop())
                if len(y)!=0: 
                    j=int(y.pop())
                sum=str((i+j+grade)%2) + sum
                grade=(i+j+grade)/2
            else:
                if grade!=0:
                    sum= str(grade)+sum
            return sum

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.