Advertisement
smj007

Untitled

Mar 15th, 2025
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. class Solution:
  2.     def plusOne(self, digits: List[int]) -> List[int]:
  3.        
  4.         z = len(digits) - 1
  5.         carry = 1
  6.        
  7.         while (z>=0 and carry>0):
  8.             carry = (digits[z] + 1)//10
  9.             digits[z] = (digits[z] + 1)%10
  10.             z = z - 1
  11.            
  12.         if carry > 0:
  13.             digits = [1] + digits
  14.            
  15.         return digits
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement