class Solution:
def addBinary(self, a, b):
"""
:type a: str
:type b: str
:rtype: str
"""
# Approach #1
# return bin(int(a,2)+int(b,2))[2:]
# Appraoch #2
# format()函数直接转换进制。 二进制(b)、十进制(d)、八进制(o)、十六进制(x)
return format(int(a,2)+int(b,2),"b")
leetcode 67. 二进制求和 python Add Binary 一行代码 int(x,2) bin() format(x,'b')
猜你喜欢
转载自blog.csdn.net/huhehaotechangsha/article/details/80899693
今日推荐
周排行