leetcode刷题 6667

    xiaoxiao2022-07-14  172

    大神做法

    class Solution: def plusOne(self, digits: List[int]) -> List[int]: for i in range(len(digits)-1, -1, -1): if digits[i] < 9: digits[i] += 1 return digits digits[i] = 0 return [1] + digits class Solution: def plusOne(self, digits: List[int]) -> List[int]: res = [] carry = 1 for d in digits[::-1]: res.append((d+carry)) carry = (d+carry) // 10 if carry: res.append(carry) return res[::-1]

    class Solution: def addBinary(self, a: str, b: str) -> str: #return str(bin((int(a,2)+int(b,2))))[2:] res, carry = '', 0 i, j = len(a) - 1, len(b) - 1 while i >= 0 or j >= 0 or carry: curval = (i >= 0 and a[i] == '1') + (j >= 0 and b[j] == '1') carry, rem = divmod(curval + carry, 2) res = str(rem) + res i -= 1 j -= 1 return res 刘润森! 认证博客专家 Python Java 前端 17年就读于东莞XX学院化学工程与工艺专业,GitChat作者。Runsen的微信公众号是"Python之王",因为Python入了IT的坑,从此不能自拔。公众号内容涉及Python,Java计算机、杂谈。干货与情怀同在。喜欢的微信搜索:「Python之王」。个人微信号:RunsenLiu。不关注我公号一律拉黑!!!
    最新回复(0)