摘要:
逐位计算 思路: 遍历字符串,逐位加和,用一个变量记录是否产生进位。 class Solution: def addBinary(self, a: str, b: str) -> str: res = '' if len(a)<len(b): a,b = b,a temp = 0 for i in 阅读全文
posted @ 2020-06-08 18:07
nil_f
阅读(107)
评论(0)
推荐(0)
摘要:
一次遍历 思路: 从后向前遍历数组,把相应位置数字加一,同时对10取余,如果不为0,则直接返回加1后的数组,如果为0,代表当前位置的数为9,继续遍历。如果遍历结束都没有返回结果,代表每一位数字均为9,则加一后的结果为原数组长度加一,第一位为1,其余为0。 代码: class Solution: de 阅读全文
posted @ 2020-06-08 17:36
nil_f
阅读(151)
评论(0)
推荐(0)