Add Binary
Question
Given two binary strings, return their sum (also a binary string).
Example
For example, a = "11"
b = "1"
Return "100"
.
Answer
solution:
Knowledge:
这道题目我投机取巧了一把,使用了高级语言python,就不用按位操作了...我一直认为要发挥高级语言的优势嘛...
python中的进制转换,十进制是int类型,而另一种进制是字符串,往往有"0b"等标识符。
二进制转十进制:int(x, base=2) #if base is given, then x must be a string
十进制转二进制:bin(number) #Return the binary representation of an integer
Last updated
Was this helpful?