|
11 | 11 |
|
12 | 12 | ## [989. Add to Array-Form of Integer (Easy)](https://leetcode.com/problems/add-to-array-form-of-integer "数组形式的整数加法") |
13 | 13 |
|
14 | | -<p>For a non-negative integer <code>X</code>, the <em>array-form of <code>X</code></em> is an array of its digits in left to right order. For example, if <code>X = 1231</code>, then the array form is <code>[1,2,3,1]</code>.</p> |
| 14 | +<p>The <strong>array-form</strong> of an integer <code>num</code> is an array representing its digits in left to right order.</p> |
15 | 15 |
|
16 | | -<p>Given the array-form <code>A</code> of a non-negative integer <code>X</code>, return the array-form of the integer <code>X+K</code>.</p> |
| 16 | +<ul> |
| 17 | + <li>For example, for <code>num = 1321</code>, the array form is <code>[1,3,2,1]</code>.</li> |
| 18 | +</ul> |
17 | 19 |
|
18 | | -<p> </p> |
19 | | - |
20 | | -<ol> |
21 | | -</ol> |
| 20 | +<p>Given <code>num</code>, the <strong>array-form</strong> of an integer, and an integer <code>k</code>, return <em>the <strong>array-form</strong> of the integer</em> <code>num + k</code>.</p> |
22 | 21 |
|
23 | | -<div> |
| 22 | +<p> </p> |
24 | 23 | <p><strong>Example 1:</strong></p> |
25 | 24 |
|
26 | 25 | <pre> |
27 | | -<strong>Input: </strong>A = <span id="example-input-1-1">[1,2,0,0]</span>, K = 34 |
28 | | -<strong>Output: </strong><span id="example-output-1">[1,2,3,4]</span> |
29 | | -<strong>Explanation: </strong>1200 + 34 = 1234 |
| 26 | +<strong>Input:</strong> num = [1,2,0,0], k = 34 |
| 27 | +<strong>Output:</strong> [1,2,3,4] |
| 28 | +<strong>Explanation:</strong> 1200 + 34 = 1234 |
30 | 29 | </pre> |
31 | 30 |
|
32 | | -<div> |
33 | 31 | <p><strong>Example 2:</strong></p> |
34 | 32 |
|
35 | 33 | <pre> |
36 | | -<strong>Input: </strong>A = <span id="example-input-2-1">[2,7,4]</span>, K = <span id="example-input-2-2">181</span> |
37 | | -<strong>Output: </strong><span id="example-output-2">[4,5,5]</span> |
38 | | -<strong>Explanation: </strong>274 + 181 = 455 |
| 34 | +<strong>Input:</strong> num = [2,7,4], k = 181 |
| 35 | +<strong>Output:</strong> [4,5,5] |
| 36 | +<strong>Explanation:</strong> 274 + 181 = 455 |
39 | 37 | </pre> |
40 | 38 |
|
41 | | -<div> |
42 | 39 | <p><strong>Example 3:</strong></p> |
43 | 40 |
|
44 | 41 | <pre> |
45 | | -<strong>Input: </strong>A = <span id="example-input-3-1">[2,1,5]</span>, K = <span id="example-input-3-2">806</span> |
46 | | -<strong>Output: </strong><span id="example-output-3">[1,0,2,1]</span> |
47 | | -<strong>Explanation: </strong>215 + 806 = 1021 |
| 42 | +<strong>Input:</strong> num = [2,1,5], k = 806 |
| 43 | +<strong>Output:</strong> [1,0,2,1] |
| 44 | +<strong>Explanation:</strong> 215 + 806 = 1021 |
48 | 45 | </pre> |
49 | 46 |
|
50 | | -<div> |
51 | 47 | <p><strong>Example 4:</strong></p> |
52 | 48 |
|
53 | 49 | <pre> |
54 | | -<strong>Input: </strong>A = <span id="example-input-4-1">[9,9,9,9,9,9,9,9,9,9]</span>, K = <span id="example-input-4-2">1</span> |
55 | | -<strong>Output: </strong><span id="example-output-4">[1,0,0,0,0,0,0,0,0,0,0]</span> |
56 | | -<strong>Explanation: </strong>9999999999 + 1 = 10000000000 |
| 50 | +<strong>Input:</strong> num = [9,9,9,9,9,9,9,9,9,9], k = 1 |
| 51 | +<strong>Output:</strong> [1,0,0,0,0,0,0,0,0,0,0] |
| 52 | +<strong>Explanation:</strong> 9999999999 + 1 = 10000000000 |
57 | 53 | </pre> |
58 | 54 |
|
59 | 55 | <p> </p> |
60 | | - |
61 | | -<p><strong>Note:</strong></p> |
62 | | - |
63 | | -<ol> |
64 | | - <li><code>1 <= A.length <= 10000</code></li> |
65 | | - <li><code>0 <= A[i] <= 9</code></li> |
66 | | - <li><code>0 <= K <= 10000</code></li> |
67 | | - <li>If <code>A.length > 1</code>, then <code>A[0] != 0</code></li> |
68 | | -</ol> |
69 | | -</div> |
70 | | -</div> |
71 | | -</div> |
72 | | -</div> |
| 56 | +<p><strong>Constraints:</strong></p> |
| 57 | + |
| 58 | +<ul> |
| 59 | + <li><code>1 <= num.length <= 10<sup>4</sup></code></li> |
| 60 | + <li><code>0 <= num[i] <= 9</code></li> |
| 61 | + <li><code>num</code> does not contain any leading zeros except for the zero itself.</li> |
| 62 | + <li><code>1 <= k <= 10<sup>4</sup></code></li> |
| 63 | +</ul> |
73 | 64 |
|
74 | 65 | ### Related Topics |
75 | 66 | [[Array](../../tag/array/README.md)] |
|
0 commit comments