Skip to content

Latest commit

 

History

History
44 lines (27 loc) · 1.11 KB

File metadata and controls

44 lines (27 loc) · 1.11 KB

67. Add Binary - 二进制求和

给定两个二进制字符串,返回他们的和(用二进制表示)。

输入为非空字符串且只包含数字 1 和 0

示例 1:

输入: a = "11", b = "1"
输出: "100"

示例 2:

输入: a = "1010", b = "1011"
输出: "10101"

题目标签:Math / String

题目链接:LeetCode / LeetCode中国

题解

Language Runtime Memory
python3 92 ms N/A
class Solution:
    def addBinary(self, a, b):
        """
        :type a: str
        :type b: str
        :rtype: str
        """
        return bin(int(a, 2) + int(b, 2))[2:]