<jupyter_start><jupyter_text>66. Plus One  ContentGiven a non-empty array of decimal digits&nbsp;representing a non-negative integer, increment&nbsp;one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element in the array contains a single digit.You may assume the integer does not contain any leading zero, except the number 0 itself.&nbsp;Example 1:Input: digits = [1,2,3]Output: [1,2,4]Explanation: The array represents the integer 123.Example 2:Input: digits = [4,3,2,1]Output: [4,3,2,2]Explanation: The array represents the integer 4321.Example 3:Input: digits = [0]Output: [1]&nbsp;Constraints:	1 &lt;= digits.length &lt;= 100	0 &lt;= digits[i] &lt;= 9  Difficulty: Easy, AC rate: 42.0% Question Tags:- Array- Math Links: 🎁 [Question Detail](https://leetcode.com/problems/plus-one/description/) | 🎉 [Question Solution](https://leetcode.com/problems/plus-one/solution/) | 💬 [Question Discussion](https://leetcode.com/problems/plus-one/discuss/?orderBy=most_votes) Hints:  Sample Test Case[1,2,3] ---What's your idea?简单的加法法则，注意进位即可---<jupyter_code>from typing import List

class Solution:
    def plusOne(self, digits: List[int]) -> List[int]:
        idx = len(digits) - 1
        carry = 1
        
        while carry and idx >= 0:
            digits[idx] += carry
            carry = digits[idx] // 10
            digits[idx] %= 10
            
            idx -= 1
        
        return digits if carry == 0 else [carry] + digits
s = Solution()
print(s.plusOne([1,2,3]))
print(s.plusOne([4,3,2,1]))
print(s.plusOne([0]))
print(s.plusOne([9,9]))
print(s.plusOne([9,8]))
import sys, os; sys.path.append(os.path.abspath('..'))
from submitter import submit
submit(66)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1420486700622524, 'fraction_numerical': 0.03621958121109225, 'mean_word_length': 3.830601092896175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '62252', 'license': 'MIT', 'n_tokens_mistral': 647, 'n_tokens_neox': 594, 'n_words': 171, 'path': '51-100/66.plus-one.ipynb', 'repo_name': 'Sorosliu1029/LeetCode', 'size': '1767'}