###67. Add Binary
题目: https://leetcode.com/problems/add-binary/
难度 : Easy
几种case:
- a or b 为空,最简单
- 唯一的问题是如果有进位的处理,进位的处理就是先让其中的一个数和
‘1’
做addBinary
处理 ,然后再用addBinary
class Solution(object):
def addBinary(self, a, b):
"""
:type a: str
:type b: str
:rtype: str
"""
if (a == '' or b == ''):
return a + b
elif a[-1] == '0' and b[-1] == '0':
return self.addBinary(a[:-1], b[:-1]) + '0'
elif a[-1] == '1' and b[-1] == '1':
return self.addBinary(a[:-1], self.addBinary(b[:-1],'1')) + '0'
else:
return self.addBinary(a[:-1], b[:-1]) + '1'