Created
January 29, 2015 23:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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