{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "3e790bfc8db24efb9e633e09abfa98b4",
  "keywords": "数组,数学",
  "title": "加一",
  "desc": [
    {
      "content": "\n<p>给定一个由 <strong>整数 </strong>组成的<strong> 非空</strong> 数组所表示的非负整数，在该数的基础上加一。</p><p>最高位数字存放在数组的首位， 数组中每个元素只存储<strong>单个</strong>数字。</p><p>你可以假设除了整数 0 之外，这个整数不会以零开头。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>digits = [1,2,3]<strong><br />输出：</strong>[1,2,4]<strong><br />解释：</strong>输入数组表示数字 123。</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>digits = [4,3,2,1]<strong><br />输出：</strong>[4,3,2,2]<strong><br />解释：</strong>输入数组表示数字 4321。</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>digits = [0]<strong><br />输出：</strong>[1]</pre><p> </p><p><strong>提示：</strong></p><ul>\t<li><code>1 <= digits.length <= 100</code></li>\t<li><code>0 <= digits[i] <= 9</code></li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution\n{\npublic:\n\tvector<int> plusOne(vector<int> &digits)\n\t{\n\t\tint carry = 1;\n\t\tvector<int> res;\n\t\tfor (int i = digits.size() - 1; i >= 0; i--)\n\t\t{\n\t\t\tint d = digits[i] + carry;\n\t\t\tres.push_back(d % 10);\n\t\t\tcarry = d / 10;\n\t\t}\n\t\tif (carry > 0)\n\t\t{\n\t\t\tres.push_back(carry);\n\t\t}\n\t\treverse(res.begin(), res.end());\n\t\treturn res;\n\t}\n};",
    "language": "cpp"
  },
  "node_id": "dailycode-f5e6dbdb903048868b02fc2916a4c8b3",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600469823"
}