#66
Plus One
easy· Math & Geometryruns: 0You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant, and the integer does not contain any leading zero. Increment the large integer by one and return the resulting array of digits.
sign in to paste and practice your own solution
wpm 0acc 100%time 0:000 / 265
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
click the box to focus · tab inserts 4 spaces · backspace to correct · esc to pause
desktop only
codedrill is a typing game and needs a real keyboard. open this on a laptop or desktop to practice.
you can still browse problems and sections from your phone.