Here are two binary strings , Returns the sum of them ( In binary ).
Input is Non empty String and contains only numbers 1
and 0
.
for example :
Input : a = "11", b = "1" Output : "100"
Consider the simplest approach : First the a and b Convert to decimal , Sum and convert to binary numbers .
class Solution:
def addBinary(self, a: str, b: str) -> str:
return bin(int(a, 2) + int(b, 2))[2:]
#int(x, base=10),base The default is 10 Base number
# bin() Returns an integer int Or long integers longint The binary representation of .
a = "11"
b = "1"
S = Solution()
result = S.addBinary(a,b)
print(result)