Nav: << previous: 65.有效数字 | next: 67.二进制求和 >>
Description
tab: English
<p>You are given a <strong>large integer</strong> represented as an integer array <code>digits</code>, where each <code>digits[i]</code> is the <code>i<sup>th</sup></code> digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading <code>0</code>'s.</p>
<p>Increment the large integer by one and return <em>the resulting array of digits</em>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> digits = [1,2,3]
<strong>Output:</strong> [1,2,4]
<strong>Explanation:</strong> The array represents the integer 123.
Incrementing by one gives 123 + 1 = 124.
Thus, the result should be [1,2,4].
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> digits = [4,3,2,1]
<strong>Output:</strong> [4,3,2,2]
<strong>Explanation:</strong> The array represents the integer 4321.
Incrementing by one gives 4321 + 1 = 4322.
Thus, the result should be [4,3,2,2].
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> digits = [9]
<strong>Output:</strong> [1,0]
<strong>Explanation:</strong> The array represents the integer 9.
Incrementing by one gives 9 + 1 = 10.
Thus, the result should be [1,0].
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= digits.length <= 100</code></li>
<li><code>0 <= digits[i] <= 9</code></li>
<li><code>digits</code> does not contain any leading <code>0</code>'s.</li>
</ul>
---
[submissions](https://leetcode.com/problems/plus-one/submissions/) | [solutions](https://leetcode.com/problems/plus-one/solutions/)
tab: 中文
<p>给定一个表示 <strong>大整数</strong> 的整数数组 <code>digits</code>,其中 <code>digits[i]</code> 是整数的第 <code>i</code> 位数字。这些数字按从左到右,从最高位到最低位排列。这个大整数不包含任何前导 <code>0</code>。</p>
<p>将大整数加 1,并返回结果的数字数组。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>digits = [1,2,3]
<strong>输出:</strong>[1,2,4]
<strong>解释:</strong>输入数组表示数字 123。
加 1 后得到 123 + 1 = 124。
因此,结果应该是 [1,2,4]。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>digits = [4,3,2,1]
<strong>输出:</strong>[4,3,2,2]
<strong>解释:</strong>输入数组表示数字 4321。
加 1 后得到 4321 + 1 = 4322。
因此,结果应该是 [4,3,2,2]。
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入:</strong>digits = [9]
<strong>输出:</strong>[1,0]
<strong>解释:</strong>输入数组表示数字 9。
加 1 得到了 9 + 1 = 10。
因此,结果应该是 [1,0]。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= digits.length <= 100</code></li>
<li><code>0 <= digits[i] <= 9</code></li>
<li><code>digits</code> 不包含任何前导 <code>0</code>。</li>
</ul>
---
[提交记录](https://leetcode.cn/problems/plus-one/submissions/) | [题解](https://leetcode.cn/problems/plus-one/solution/)
Solutions & Notes
properties:
note.updated:
displayName: Last Updated
note.relative_links:
displayName: Related Links
note.desc:
displayName: Description
note.grade:
displayName: Rating
note.program_language:
displayName: Language
note.time_complexity:
displayName: TC
note.space_complexity:
displayName: SC
views:
- type: table
name: Solutions & Notes
filters:
and:
- file.hasLink(this.file)
- file.tags.containsAny("leetcode/solution", "leetcode/note")
order:
- file.name
- desc
- program_language
- time_complexity
- space_complexity
- grade
- relative_links
- updated
sort:
- property: grade
direction: ASC
- property: time_complexity
direction: ASC
- property: program_language
direction: ASC
columnSize:
file.name: 104
note.space_complexity: 65
note.grade: 126
Similar Problems
properties:
note.lcTopics:
displayName: Topics
note.lcAcRate:
displayName: AC Rate
note.favorites:
displayName: Favorites
note.grade:
displayName: Rating
note.translatedTitle:
displayName: Title (CN)
note.lcDifficulty:
displayName: Difficulty
views:
- type: table
name: Similar Problems
filters:
and:
- file.hasLink(this.file)
- similarQuestions.contains(this.file)
order:
- file.name
- translatedTitle
- lcTopics
- lcDifficulty
- lcAcRate
- grade
- favorites
sort:
- property: file.name
direction: ASC
- property: lcTopics
direction: DESC
columnSize:
note.translatedTitle: 240
note.lcTopics: 347
note.lcAcRate: 75
note.grade: 122