-
Notifications
You must be signed in to change notification settings - Fork 161
/
add-to-array-form-of-integer.md
59 lines (45 loc) · 1.89 KB
/
add-to-array-form-of-integer.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<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>
<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>
<p> </p>
<ol>
</ol>
<div>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>A = <span id="example-input-1-1">[1,2,0,0]</span>, K = 34
<strong>Output: </strong><span id="example-output-1">[1,2,3,4]</span>
<strong>Explanation: </strong>1200 + 34 = 1234
</pre>
<div>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input: </strong>A = <span id="example-input-2-1">[2,7,4]</span>, K = <span id="example-input-2-2">181</span>
<strong>Output: </strong><span id="example-output-2">[4,5,5]</span>
<strong>Explanation: </strong>274 + 181 = 455
</pre>
<div>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input: </strong>A = <span id="example-input-3-1">[2,1,5]</span>, K = <span id="example-input-3-2">806</span>
<strong>Output: </strong><span id="example-output-3">[1,0,2,1]</span>
<strong>Explanation: </strong>215 + 806 = 1021
</pre>
<div>
<p><strong>Example 4:</strong></p>
<pre>
<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>
<strong>Output: </strong><span id="example-output-4">[1,0,0,0,0,0,0,0,0,0,0]</span>
<strong>Explanation: </strong>9999999999 + 1 = 10000000000
</pre>
<p> </p>
<p><strong>Note:</strong></p>
<ol>
<li><code>1 <= A.length <= 10000</code></li>
<li><code>0 <= A[i] <= 9</code></li>
<li><code>0 <= K <= 10000</code></li>
<li>If <code>A.length > 1</code>, then <code>A[0] != 0</code></li>
</ol>
</div>
</div>
</div>
</div>