Given two binary strings, return their sum (in binary representation).
The input is a non- empty string and contains only numbers 1
and sums 0
.
Example 1:
Input: a = "11", b = "1" Output: "100"
Example 2:
Input: a = "1010", b = "1011" Output: "10101"
class Solution: def addBinary(self, a, b): """ :type a: str :type b: str :rtype: str """ intNum=int(a,2)+int(b,2)# Convert binary to decimal, then sum return bin(intNum)[2:]# When the decimal is converted to binary, the first two digits are 0b, which needs to be removed