[勇者闯LeetCode] 66. Plus One
Description
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
You may assume the integer do not contain any leading zero, except the number 0 itself.
The digits are stored such that the most significant digit is at the head of the list.
Information
- Tags: Array | Math
- Difficulty: Easy
Solution
注意进位
class Solution(object):
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
for i in range(-1, -(len(digits)+1), -1):
plus_one = digits[i] + 1
digits[i] = plus_one % 10
if plus_one < 10:
return digits
return [1] + digits