-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
989.cpp
55 lines (53 loc) · 1.48 KB
/
989.cpp
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
__________________________________________________________________________________________________
sample 104 ms submission
auto speedup =[]() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return nullptr;
}();
class Solution {
public:
vector<int> addToArrayForm(vector<int>& A, int K)
{
vector<int> out;
for (int i = A.size() - 1; K > 0 || i >= 0; K /= 10) {
if (i >= 0)
K += A[i--];
out.push_back(K % 10);
}
reverse(out.begin(), out.end());
return out;
}
};
__________________________________________________________________________________________________
sample 12356 kb submission
class Solution {
public:
vector<int> addToArrayForm(vector<int>& A, int K) {
int step = 0,i=A.size()-1,temp;
while (K!=0||step!=0){
temp = K%10;
if(i>=0){
temp = temp + step+A[i];
step = temp>=10?1:0;
temp = step?temp-10:temp;
A[i] = temp;
i--;
}else{
temp+=step;
step = temp>=10?1:0;
temp = step?temp-10:temp;
A.insert(A.begin(),temp);
}
K/=10;
}
return A;
}
};
static auto speedup = [](){
ios::sync_with_stdio(false);
cin.tie(nullptr);
return nullptr;
}();
__________________________________________________________________________________________________