Blue Bridge Cup (Part 5: Binary Summation)

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.

Guess you like

Origin blog.csdn.net/h1998040218/article/details/129957902