1. Problem description:
Given the a
sum of two binary strings b
, return their sum as a binary string.
2. Problem-solving ideas:
Convert the obtained binary string to a decimal number, then sum, and then convert the result to a binary character and return
3. Code debugging
class Solution:
def addBinary(self, a: str, b: str) -> str:
Sum = int(a,2)+int(b,2)
return str(bin(Sum))[2:]
4. Running results
problem solved.