Skip to content

Instantly share code, notes, and snippets.

@jones
Created January 29, 2015 23:08
Show Gist options
  • Save jones/a82b4a9ec20e4b6ec0d1 to your computer and use it in GitHub Desktop.
Save jones/a82b4a9ec20e4b6ec0d1 to your computer and use it in GitHub Desktop.
Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list.
class Solution:
# @param digits, a list of integer digits
# @return a list of integer digits
def plusOne(self, digits):
for i in reversed(range(len(digits))):
digits[i] = (digits[i] + 1) % 10
if digits[i] == 0:
continue
return digits
return [1,]+digits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment