We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 10e2db8 commit 80055cfCopy full SHA for 80055cf
C++/add-to-array-form-of-integer.cpp
@@ -0,0 +1,25 @@
1
+// Time: O(n + logk)
2
+// Space: O(1)
3
+
4
+class Solution {
5
+public:
6
+ vector<int> addToArrayForm(vector<int>& A, int K) {
7
+ reverse(A.begin(), A.end());
8
+ int carry = K, i = 0;
9
+ A[i] += carry;
10
+ carry = A[i] / 10;
11
+ A[i] %= 10;
12
+ while (carry) {
13
+ ++i;
14
+ if (i < A.size()) {
15
16
+ } else {
17
+ A.emplace_back(carry);
18
+ }
19
20
21
22
23
+ return A;
24
25
+};
0 commit comments