Python3 solution

  • 0
    class Solution:
        def addBinary(self, a, b):
            :type a: str
            :type b: str
            :rtype: str
            return bin(int(a, 2)+int(b, 2))[2:]

    We can use 'int' to convert input strings to decimal number. Then use bin which stands for binary to convert decimal number to binary string. Finally drop the first two characters '0b'.

Log in to reply

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