Skip to content

Latest commit

 

History

History
16 lines (16 loc) · 410 Bytes

66.md

File metadata and controls

16 lines (16 loc) · 410 Bytes

解法一

  • 40ms
  • 41%
class Solution:
    def plusOne(self, digits: List[int]) -> List[int]:
        carry = 1
        n = len(digits)
        if n == 0: return digits
        for idx in range(len(digits)-1, -1, -1):
            carry, digits[idx] = divmod(carry+digits[idx], 10)
            if carry == 0: break
        if carry == 0:
            return digits
        return [carry] + digits